Angular 7 Platform-Browser-Dynamic(中间值).share不是函数

时间:2018-11-21 14:50:22

标签: angular typescript webpack rxjs angular7

我将Angular 5的版本更新为7,安装了webpack 4之后,rxjs 6.3.3和angular 7.0.3以及照顾了依赖关系,我得到了要编译的捆绑包。但是,当尝试将应用程序组件绑定到其选择器时,就会发生这种难以追踪的错误。

t_Host.ngfactory.js? [sm]:1 ERROR TypeError: (intermediate value).share is not a function at new t (platform-browser-dynamic.js:314)

这是我的main.ts文件(引导我的组件的文件):

import { tap, mapTo, share } from 'rxjs/operators';
import { platformBrowserDynamic } from '@angular/platform- 
browser-dynamic';

import { AppModule } from './app.module';

const platform = platformBrowserDynamic();
platform.bootstrapModule(AppModule);

这是我的vendor.ts文件:

import '@angular/platform-browser';
import '@angular/platform-browser-dynamic';
import '@angular/core';
import '@angular/common';
import '@angular/forms';
import '@angular/http';
import '@angular/router';
import '@ng-bootstrap/ng-bootstrap';
import 'ngx-scrollspy';

import 'rxjs/operators/map';
import 'rxjs/operators/mergeMap';
import 'rxjs/operators/share';

以下是生成的头脚本导入(似乎是正确的顺序):

<script type="text/javascript" src="0.chunk.js" defer> </script>
<script type="text/javascript" src="polyfills.bundle.js" defer></script>
<script type="text/javascript" src="vendor.bundle.js" defer></script>
<script type="text/javascript" src="main.bundle.js" defer></script></head>

最后是package.json的相关部分:

"dependencies": {
...
"@angular/animations": "7.0.4",
"@angular/cli": "7.0.6",
"@angular/common": "7.0.4",
"@angular/compiler": "7.0.4",
"@angular/core": "7.0.4",
"@angular/forms": "7.0.4",
"@angular/http": "7.0.4",
"@angular/platform-browser": "7.0.4",
"@angular/platform-browser-dynamic": "7.0.4",
"@angular/platform-server": "7.0.4",
"@angular/router": "7.0.4",
"@angular/upgrade": "7.0.4",
...
"rxjs": "6.3.3",
"rxjs-compat": "6.3.3",
...
"devDependencies": {
...
"@ngtools/webpack": "7.0.6",
"awesome-typescript-loader": "5.2.1",
...
"typescript": "3.1.1",
"webpack": "4.26.0",
"webpack-cli": "3.1.2",
"webpack-dev-middleware": "3.4.0",
"webpack-dev-server": "3.1.10",
"webpack-md5-hash": "0.0.5",
"webpack-merge": "1.0.1"
...
}

更新:我尝试使用在https://github.com/ReactiveX/rxjs-tslint中找到的rxjs linter,它导致“找不到任何可能的迁移”。所以我认为我迁移正确。

1 个答案:

答案 0 :(得分:0)

在撰写本文时,问题是RXJS 6.3.3似乎不适用于Angular。我现在不得不降级到6.2.2。这解决了我的问题。

 "dependencies": {
   ...
   "rxjs": "6.2.2",
   "rxjs-compat": "6.2.2",
   ...
 }