【问题标题】:Typescript : How to resolve 'rxjs/Rx has no exported member 'SubscriptionLike'打字稿:如何解决 'rxjs/Rx 没有导出的成员 'SubscriptionLike'
【发布时间】:2018-09-01 22:10:39
【问题描述】:

我正在尝试在https://www.youtube.com/watch?v=gxCu5TEmxXE 此处遵循此示例,但是在执行tsc -p 时,出现错误。有什么需要导入的吗?

错误:

node_modules/@angular/common/src/location/location.d.ts(1,10): error TS2305: Module '"...functions/node_modules/rxjs/Rx"' has no exported member 'SubscriptionLike'.

TS 文件

import "zone.js/dist/zone-node";
import * as functions from "firebase-functions";
import * as express from "express"
import { renderModuleFactory } from "@angular/platform-server"
import * as fs from "fs"

const document = fs.readFileSync(__dirname + "/dist-server/index.html", "utf8");
const AppServerModuleNgFactory = require(__dirname + "/dist-server/main.bundle");

const app = express();
app.get("**", (req, res) => {
    const url = req.path;
    renderModuleFactory(AppServerModuleNgFactory, { document, url }).then(html => {
        res.send(html);
    });
});
exports.post = functions.https.onRequest(app);

配置

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2015",
    "rootDir": ".",
    "outDir": "../functions"
  },
  "files": [
    "index.ts"
  ]
}

【问题讨论】:

  • 认为你应该重新安装 @angular 包,它在我的版本中不存在。
  • @rrd 刚刚卸载,npm i @angular/platform-server,同样的错误。

标签: javascript angular typescript firebase google-cloud-functions


【解决方案1】:

关注后我也遇到了同样的问题

Following this tutorial from djamware

经过大量搜索,我发现Angular 6不支持通过本教程中的说明安装的Rxjs包。

Angular 6 不适用于 RxJS 5.5,但适用于 RxJS 6。

npm i rxjs@6

在 cli 中运行上述命令应该可以解决您的问题。在我的情况下确实如此。

【讨论】:

  • 你不应该运行npm i rxjs@6 --save吗?
  • @dudewad 从 npm 5.0.0 开始,已安装的模块默认添加为依赖项,因此不再需要 --save 选项。
【解决方案2】:

我敢打赌,如果您查看 package.json,您会看到很多 beta angular 软件包版本。您可以降级到release version,或者,如果出于某种奇怪的原因您需要继续使用测试版,您可以编辑该location.d.ts 文件并将该文件中使用SubcriptionLike 的两个位置更改为仅@ 987654328@。同样,这是超级hacky,每次运行npm install 时都会被清除,并且只有在您出于某种原因需要使用beta 时才应该使用它。 package.json 中的依赖项应该看起来像这样(尽管我的依赖项是为 ionic 准备的):

"dependencies": {
  "@angular/cli": "^1.7.3",
  "@angular/common": "^5.2.9",
  "@angular/compiler": "^5.2.9",
  "@angular/compiler-cli": "^5.2.9",
  "@angular/core": "^5.2.9",
  "@angular/forms": "^5.2.9",
  "@angular/http": "^5.2.9",
  "@angular/platform-browser": "^5.2.9",
  "@angular/platform-browser-dynamic": "^5.2.9",
  "@angular/tsc-wrapped": "^4.4.6",
  "@ionic-native/core": "4.4.0",
  "@ionic-native/splash-screen": "4.4.0",
  "@ionic-native/status-bar": "4.4.0",
  "@ionic/pro": "1.0.17",
  "@ionic/storage": "2.1.3",
  "ionic-angular": "3.9.2",
  "ionicons": "3.0.0",
  "rxjs": "^5.5.6",
  "sw-toolbox": "3.6.0",
  "zone.js": "0.8.18"
}

【讨论】:

【解决方案3】:

rxjs 的最新版本是 6.9.0 要解决此问题,您必须更新 rxjs 包。 运行ng update rxjs

【讨论】:

猜你喜欢
  • 2018-11-13
  • 2017-12-29
  • 2018-10-20
  • 2018-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-09-05
  • 1970-01-01
相关资源
最近更新 更多