从'rxjs / operators / take'导入{take}但是'rxjs / operators / take'文件夹不存在

时间:2017-12-15 11:55:17

标签: angular rxjs angular-material

我正在使用Visual Studio的Angular模板开发Angular 2应用程序。对于Web服务,我使用的是ASP.NET Core 2.这是package.json文件内容:

{
  "name": "AngularWebApplication",
  "private": true,
  "version": "0.0.0",
  "scripts": {
    "test": "karma start ClientApp/test/karma.conf.js"
  },
  "dependencies": {
    "@angular/animations": "5.1.0",
    "@angular/cdk": "5.0.1",
    "@angular/common": "5.1.0",
    "@angular/compiler": "5.1.0",
    "@angular/compiler-cli": "5.1.0",
    "@angular/core": "5.1.0",
    "@angular/forms": "5.1.0",
    "@angular/http": "5.1.0",
    "@angular/material": "5.0.1",
    "@angular/platform-browser": "5.1.0",
    "@angular/platform-browser-dynamic": "5.1.0",
    "@angular/platform-server": "5.1.0",
    "@angular/router": "5.1.0",
    "@ngtools/webpack": "1.9.0",
    "@types/webpack-env": "1.13.0",
    "angular2-template-loader": "0.6.2",
    "aspnet-prerendering": "^3.0.1",
    "aspnet-webpack": "^2.0.1",
    "awesome-typescript-loader": "3.2.1",
    "bootstrap": "3.3.7",
    "css": "2.2.1",
    "css-loader": "0.28.4",
    "es6-shim": "0.35.3",
    "event-source-polyfill": "0.0.9",
    "expose-loader": "0.7.3",
    "extract-text-webpack-plugin": "2.1.2",
    "file-loader": "0.11.2",
    "html-loader": "0.4.5",
    "isomorphic-fetch": "2.2.1",
    "jquery": "3.2.1",
    "json-loader": "0.5.4",
    "mdn-polyfills": "^5.2.0",
    "preboot": "4.5.2",
    "raw-loader": "0.5.1",
    "reflect-metadata": "0.1.10",
    "rxjs": "5.5.5",
    "style-loader": "0.18.2",
    "to-string-loader": "1.1.5",
    "typescript": "2.4.2",
    "url-loader": "0.5.9",
    "webpack": "2.5.1",
    "webpack-hot-middleware": "2.18.2",
    "webpack-merge": "4.1.0",
    "zone.js": "0.8.12"
  },
  "devDependencies": {
    "@types/chai": "4.0.1",
    "@types/jasmine": "2.5.53",
    "chai": "4.0.2",
    "jasmine-core": "2.6.4",
    "karma": "1.7.0",
    "karma-chai": "0.1.0",
    "karma-chrome-launcher": "2.2.0",
    "karma-cli": "1.0.1",
    "karma-jasmine": "1.1.0",
    "karma-webpack": "2.0.3"
  }
}

我添加了@angular/material然后我需要将所有@angular软件包更新到5.1.0版本,其中一些软件包更新到5.0.1版本。我还将rxjs更新为5.5.5版本。

当我启动应用程序时,我收到错误:

  

NodeInvocationException:由于错误,预渲染失败:错误:   找不到模块“rxjs / operators / take”

但我在文件夹\node_modules\rxjs\operators\中找到了以下文件:

  • take.d.ts
  • take.js
  • take.js.map
  • takeLast.d.ts
  • takeLast.js
  • takeLast.js.map
  • takeUntil.d.ts
  • takeUntil.js
  • takeUntil.js.map
  • takeWhile.d.ts
  • takeWhile.js
  • takeWhile.js.map

问题是node_modules中有几个文件我没有修改,导入如下:

import { take } from 'rxjs/operators/take'

我认为我不必在node_modules文件夹中修改这些文件以从路径中移除摘录(from 'rxjs/operators')。

我还没有成功运行npm install -g @angular/cli

我该如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

对我来说,这是由于角度版本的不匹配。 跑

sudo npm install -g @angular/cli

并且构建,它对我有用。

答案 1 :(得分:0)

您需要在服务/组件

中将其用作import { take } from 'rxjs/operators'
import { take } from 'rxjs/operators';

答案 2 :(得分:0)

@Kirk-Larkinanswer on another SO post,

  

安装完更新版本后,您需要让webpack以正确的顺序重建。您可以通过项目的解决方案级别重建来实现这一点,但如果没有,您可以运行以下命令来强制webpack正确构建:

     

webpack --config webpack.config.vendor.js

     

webpack

这一点,加上rxjs升级到v5.5.0,为我解决了这个问题。