javascript rxjs/Subscription 没有导出成员“订阅”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50176029/
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
rxjs/Subscription has no exported member 'Subscription'
提问by ?ystein Seel
I updated my angular project and all my dependencies to latest version. Without to much trouble I solved most of the dependency issues, but I'm still stuck on RxJS. Here is my package.json:
我将我的 angular 项目和所有依赖项更新到最新版本。我很轻松地解决了大部分依赖问题,但我仍然坚持使用 RxJS。这是我的 package.json:
"dependencies": {
"@angular-devkit/build-angular": "^0.6.0",
"@angular/animations": "^6.0.0",
"@angular/common": "^6.0.0",
"@angular/compiler": "^6.0.0",
"@angular/core": "^6.0.0",
"@angular/forms": "^6.0.0",
"@angular/http": "^6.0.0",
"@angular/platform-browser": "^6.0.0",
"@angular/platform-browser-dynamic": "^6.0.0",
"@angular/router": "^6.0.0",
"angular-bootstrap-md": "^6.0.1",
"core-js": "^2.5.5",
"font-awesome": "^4.7.0",
"rxjs": "^6.1.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/cli": "~6.0.0",
"@angular/compiler-cli": "^6.0.0",
"@angular/language-service": "6.0.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"electron": "^1.8.3",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.2",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.4.2",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^1.0.0",
"protractor": "~5.3.1",
"ts-node": "~6.0.2",
"tslint": "~5.10.0",
"typescript": "~2.7.2"
I'm only importing two modules from RxJS:
我只从 RxJS 导入两个模块:
import { fromPromise } from 'rxjs/observable/fromPromise';
import { Subscription } from 'rxjs/Subscription';
They are both giving the same error:
他们都给出了同样的错误:
[ts] Module '"***/node_modules/rxjs/Subscription"' has no exported
member 'Subscription'.
It's exactly the same for fromPromise. Here is the error message I'm getting from Subscribtion.d.ts(I have not modified the code in any way)
对于fromPromise. 这是我收到的错误消息Subscribtion.d.ts(我没有以任何方式修改代码)
UPDATE:
更新:
The answers bellow solved the issue with Subscription but fromPromisestill gives the same issue even though it's exported correctly:
下面的答案解决了订阅问题,但fromPromise即使正确导出,仍然存在相同的问题:
export * from 'rxjs-compat/observable/fromPromise';
export * from 'rxjs-compat/observable/fromPromise';
回答by Alexandre Annic
There is a lot of breaking changes with RxJS 6. For example, prototype methods as
RxJS 6 有很多重大变化。例如,原型方法作为
myObservable.map(data => data * 2)
won't work anymore and must be replaced by
将不再工作,必须由
myObservable.pipe(map(data => data * 2))
All details can be found here: https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md
所有详细信息都可以在这里找到:https: //github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md
Until you have fixed all breaking changes, you can make your old code work again with rxjs-compat(https://github.com/ReactiveX/rxjs/tree/master/compat).
在修复所有破坏性更改之前,您可以使用rxjs-compat( https://github.com/ReactiveX/rxjs/tree/master/compat)使旧代码再次工作。
This package is required to get backwards compatibility with RxJS previous to version 6. It contains the imports to add operators to
Observable.prototypeand creation methods toObservable.
需要此包才能与版本 6 之前的 RxJS 向后兼容。它包含将操作符添加
Observable.prototype到Observable.
Type this to install it:
输入以下内容进行安装:
npm install -s rxjs-compat
回答by revan
I hope your problem will resolve using this below statement
import Subscription from 'rxjs'
我希望您的问题将使用以下声明解决
import Subscription from 'rxjs'
回答by IvanS
You can fix it with this:
你可以用这个修复它:
import {from} from 'rxjs';
从 'rxjs'导入 { from};
And, instead of: return Observable.fromPromise(new Promise((resolve, reject) => {
并且,而不是: return Observable.fromPromise(new Promise((resolve, reject) => {
Now just do:
现在只做:
return from(new Promise((resolve, reject) => {
返回从(新无极((解析,拒绝)=> {
The same applies to Observable.of
这同样适用于 Observable.of
回答by Kevin ALBRECHT
afaik Angular 6 and rxjs 6 are not already compatible, for the compatibility they created https://www.npmjs.com/package/rxjs-compatyou have to install
afaik Angular 6 和 rxjs 6 尚不兼容,为了它们创建的兼容性https://www.npmjs.com/package/rxjs-compat你必须安装
[UPDATE] fromPromise is now "from". see here : https://github.com/ReactiveX/rxjs/issues/3525
[更新] fromPromise 现在是“from”。在这里看到:https: //github.com/ReactiveX/rxjs/issues/3525


