./node_modules/rxjs/_esm5/operators/index.js Angular 中的错误 6 ng build --prod of / Resolve

ERROR in ./node_modules/rxjs/_esm5/operators/index.js Angular 6 ng build --prod of / Resolve

我的应用程序在本地运行良好,但是当我想使用 ng build --prod 投入生产时,出现以下错误:

知道会发生什么吗?

ERROR in ./node_modules/rxjs/_esm5/operators/index.js Module not found: Error: Can't resolve '../internal/operators/endWith' in /Users/.../node_modules/rxjs/_esm5/operators'

package.json

{
"name": "myApp",
"version": "0.0.0",
"scripts": {
  "ng": "ng",
  "start": "ng serve",
  "build": "ng build",
  "test": "ng test",
  "lint": "ng lint",
  "e2e": "ng e2e"
},
"private": true,
"dependencies": {
  "@angular/animations": "6.0.5",
  "@angular/cdk": "^6.3.3",
  "@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/material": "^6.3.3",
  "@angular/platform-browser": "^6.0.0",
  "@angular/platform-browser-dynamic": "^6.0.0",
  "@angular/router": "^6.0.0",
  "angularfire2": "^5.0.0-rc.10",
  "bootstrap": "^4.1.1",
  "core-js": "^2.5.4",
  "firebase": "^5.0.4",
  "jquery": "^3.3.1",
  "popper.js": "^1.14.3",
  "rxjs": "^6.0.0",
  "rxjs-compat": "^6.2.2",
  "zone.js": "^0.8.26"
},
"devDependencies": {
  "@angular/compiler-cli": "^6.0.0",
  "@angular-devkit/build-angular": "~0.6.0",
  "typescript": "~2.7.2",
  "@angular/cli": "~6.0.0",
  "@angular/language-service": "^6.0.0",
  "@types/jasmine": "~2.8.6",
  "@types/jasminewd2": "~2.0.3",
  "@types/node": "~8.9.4",
  "codelyzer": "~4.2.1",
  "jasmine-core": "~2.99.1",
  "jasmine-spec-reporter": "~4.2.1",
  "karma": "~1.7.1",
  "karma-chrome-launcher": "~2.2.0",
  "karma-coverage-istanbul-reporter": "~1.4.2",
  "karma-jasmine": "~1.1.1",
  "karma-jasmine-html-reporter": "^0.2.2",
  "protractor": "~5.3.0",
  "ts-node": "~5.0.1",
  "tslint": "~5.9.1"
}
}

这些是我使用 RXJS 的地方

productos.service.ts

import { of } from 'rxjs';
...
getProductos() {
  return of(this.productos);
}

getProducto<Producto>(id) {
  return of(this.productos.find(p => p.id === id));
}

producto.resolver.service.ts

import { Injectable } from '@angular/core';
import { Router, Resolve, RouterStateSnapshot,
  ActivatedRouteSnapshot } from '@angular/router';
import { Observable } from 'rxjs';
import { map, take } from 'rxjs/operators';
import { Producto, ProductosService } from './productos.service';

@Injectable({
  providedIn: 'root'
})
export class ProductoResolver implements Resolve<Producto> {

constructor(private ps: ProductosService, private router: Router) { }

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): 
Observable<Producto> {
let id = route.paramMap.get('id');

return this.ps.getProducto(id).pipe(
  take(1),
  map(producto => {
    if (producto) {
      return producto;
    } else { // id not found
      console.error('id not found');
      this.router.navigate(['/productos']);
      return null;
    }
  })
);
}
}

看起来问题是您的 rxjs 模块损坏了。您可以尝试以下方法来修复-

  1. 尝试 npm cache clean --force 如果它不起作用然后手动删除 %appdata%\npm-cache 文件夹。

  2. 从项目中删除您的 node_modules。

  3. 使用 - npm install

  4. 重新安装所有节点模块

This error will occur when you are migrating from lower to higher angular version to another in globally, but your local angular version is same as previous

Or

RXJS may be corrupted due to some reason

Or

You may install the new version of rxjs but not clear the cache Use the below step, it resolve your problem

步骤 1:删除缓存 npm cache clean --force

第二步:删除节点模块rm -rf node_modules(可以手动删除)

步骤 3:再次安装节点模块 npm installnpm i