首页 > 解决方案 > ./node_modules/rxjs/_esm5/operators/index.js Angular 6 ng build --prod of / Resolve 中的错误

问题描述

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

知道会发生什么吗?

./node_modules/rxjs/_esm5/operators/index.js 中的错误找不到模块:错误:无法解析 /Users/.../node_modules/rxjs/_esm5/operators 中的“../internal/operators/endWith” '

包.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;
    }
  })
);
}
}

标签: angularrxjs6

解决方案


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

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

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

  3. 使用 - 重新安装所有节点模块npm install


推荐阅读