Javascript 打字稿:如何解决'rxjs/Rx 没有导出成员'SubscriptionLike'
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/49446163/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Typescript : How to resolve 'rxjs/Rx has no exported member 'SubscriptionLike'
提问by Relm
I'm trying to follow this example here https://www.youtube.com/watch?v=gxCu5TEmxXE, but when doing tsc -p, I get an error. Is there something I need to import?
我试图在这里https://www.youtube.com/watch?v=gxCu5TEmxXE遵循此示例,但是在执行此操作时tsc -p,出现错误。有什么我需要导入的吗?
ERROR:
错误:
node_modules/@angular/common/src/location/location.d.ts(1,10): error TS2305: Module '"...functions/node_modules/rxjs/Rx"' has no exported member 'SubscriptionLike'.
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 FILE
文件
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);
CONFIG
配置
{
"compilerOptions": {
"module": "commonjs",
"target": "es2015",
"rootDir": ".",
"outDir": "../functions"
},
"files": [
"index.ts"
]
}
回答by Nabil Mohammed Nalakath
I faced the same issue after following
跟随后我遇到了同样的问题
Following this tutorial from djamware
After searching a lot, I have found that Rxjs package that is installed through instructions in this tutorial is not supported with Angular 6.
经过大量搜索,我发现Angular 6不支持通过本教程中的说明安装的Rxjs包。
Angular 6 does not work with RxJS 5.5 but with RxJS 6.
Angular 6 不适用于 RxJS 5.5,但适用于 RxJS 6。
npm i rxjs@6
Run the above command in cli and that should fix your problem. It did in my case.
在 cli 中运行上述命令,应该可以解决您的问题。在我的情况下确实如此。
回答by Serj Sagan
I'd bet if you looked in your package.jsonyou'd see a lot of betaangularpackage versions. You can either downgrade to the release versionor, if for some strange reason you need to keep using the beta version, you can edit that location.d.tsfile and change the 2 places that SubcriptionLikeis used in that file to just Subscription. Again, this is super hacky, gets wiped out each time you run npm installand only should be used if you need to muck around with the betafor some reason. Your dependencies in the package.jsonshould look kind of like this (though mine is geared for ionic):
我敢打赌,如果您查看自己的内容,package.json您会看到很多betaangular软件包版本。您可以降级到发行版,或者如果出于某种奇怪的原因需要继续使用测试版,您可以编辑该location.d.ts文件并将该文件SubcriptionLike中使用的 2 个位置更改为Subscription. 再次,这是超级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"
}
回答by sumod badchhape
The latest version for rxjs is 6.9.0 To fix this issue you have to update rxjs package.
run ng update rxjs
rxjs 的最新版本是 6.9.0 要解决此问题,您必须更新 rxjs 包。跑ng update rxjs

