rxjs/Subscription 没有导出成员 'Subscription'
rxjs/Subscription has no exported member 'Subscription'
我将我的 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"
我只从 RxJS 导入两个模块:
import { fromPromise } from 'rxjs/observable/fromPromise';
import { Subscription } from 'rxjs/Subscription';
他们都给出相同的错误:
[ts] Module '"***/node_modules/rxjs/Subscription"' has no exported
member 'Subscription'.
fromPromise
完全一样。这是我从 Subscribtion.d.ts
收到的错误消息(我没有以任何方式修改代码)
更新:
下面的答案解决了 Subscription 的问题,但 fromPromise
仍然给出相同的问题,即使它已正确导出:
export * from 'rxjs-compat/observable/fromPromise';
RxJS 6 有很多重大变化。例如,原型方法
myObservable.map(data => data * 2)
将不再有效,必须由
替换
myObservable.pipe(map(data => data * 2))
可在此处找到所有详细信息:https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md
在修复所有重大更改之前,您可以使用 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.prototype
and creation methods to Observable
.
键入此内容进行安装:
npm install -s rxjs-compat
afaik Angular 6 和 rxjs 6 还不兼容,为了它们创建的兼容性 https://www.npmjs.com/package/rxjs-compat 你必须安装
[更新]
fromPromise 现在是 "from"。
看这里:https://github.com/ReactiveX/rxjs/issues/3525
你可以用这个修复它:
从'rxjs'导入{from};
并且,而不是:
return Observable.fromPromise(new Promise((resolve, reject) => {
现在就做:
return from(new Promise((resolve, reject) => {
同样适用于Observable.of
我希望您的问题可以通过以下声明得到解决
import Subscription from 'rxjs'
我将我的 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"
我只从 RxJS 导入两个模块:
import { fromPromise } from 'rxjs/observable/fromPromise';
import { Subscription } from 'rxjs/Subscription';
他们都给出相同的错误:
[ts] Module '"***/node_modules/rxjs/Subscription"' has no exported
member 'Subscription'.
fromPromise
完全一样。这是我从 Subscribtion.d.ts
收到的错误消息(我没有以任何方式修改代码)
更新:
下面的答案解决了 Subscription 的问题,但 fromPromise
仍然给出相同的问题,即使它已正确导出:
export * from 'rxjs-compat/observable/fromPromise';
RxJS 6 有很多重大变化。例如,原型方法
myObservable.map(data => data * 2)
将不再有效,必须由
替换myObservable.pipe(map(data => data * 2))
可在此处找到所有详细信息:https://github.com/ReactiveX/rxjs/blob/master/docs_app/content/guide/v6/migration.md
在修复所有重大更改之前,您可以使用 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.prototype
and creation methods toObservable
.
键入此内容进行安装:
npm install -s rxjs-compat
afaik Angular 6 和 rxjs 6 还不兼容,为了它们创建的兼容性 https://www.npmjs.com/package/rxjs-compat 你必须安装
[更新] fromPromise 现在是 "from"。 看这里:https://github.com/ReactiveX/rxjs/issues/3525
你可以用这个修复它:
从'rxjs'导入{from};
并且,而不是: return Observable.fromPromise(new Promise((resolve, reject) => {
现在就做:
return from(new Promise((resolve, reject) => {
同样适用于Observable.of
我希望您的问题可以通过以下声明得到解决
import Subscription from 'rxjs'