繁体   English   中英

将 angular 7 升级到 8 成功,但核心找不到模块 rxjs?

[英]Upgrade angular 7 to 8 successful, but core can't find module rxjs?

我将 angular 7.X 升级到了 angular 8.2.5。 这是成功的,我的应用程序仍在运行。 然而, angular/core模块抛出错误,声称它找不到rxjs 我的rxjs版本是 6.5.3,在rxjs是全新的。我已经卸载了rxjs-compat并重新运行npm install但行为没有改变。

ngserve 上的错误

(谷歌搜索的文本版本:)

ERROR in ../../../../../node_modules/@angular/core/src/application_ref.d.ts:8:28 - error TS2307: Cannot find module 'rxjs'.

8 import { Observable } from 'rxjs';
                             ~~~~~~
../../../../../node_modules/@angular/core/src/event_emitter.d.ts:8:39 - error TS2307: Cannot find module 'rxjs'.

8 import { Subject, Subscription } from 'rxjs';
                                        ~~~~~~
../../../../../node_modules/@angular/core/src/linker/query_list.d.ts:8:28 - error TS2307: Cannot find module 'rxjs'.

8 import { Observable } from 'rxjs';
                             ~~~~~~
../../../../../node_modules/@angular/core/src/util/lang.d.ts:8:28 - error TS2307: Cannot find module 'rxjs'.

8 import { Observable } from 'rxjs';

后续编译会产生类似但更紧凑的错误。 目前,这似乎不会影响我的应用程序,它仍在运行。

在此处输入图片说明

我可以尝试哪些操作来消除此错误?

包.json:

{
  "name": "myapp-ng",
  "version": "1.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": "~8.2.5",
    "@angular/cdk": "^7.3.7",
    "@angular/common": "~8.2.5",
    "@angular/compiler": "~8.2.5",
    "@angular/core": "~8.2.5",
    "@angular/forms": "~8.2.5",
    "@angular/platform-browser": "~8.2.5",
    "@angular/platform-browser-dynamic": "~8.2.5",
    "@angular/router": "~8.2.5",
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "angular2-prettyjson": "^3.0.1",
    "core-js": "^2.5.4",
    "guid-typescript": "^1.0.9",
    "install": "^0.12.2",
    "ngx-sortablejs": "^3.1.3",
    "node-sass": "^4.12.0",
    "npm": "^6.10.2",
    "rxjs": "^6.5.3",
    "sortablejs": "^1.10.0-rc3",
    "tslib": "^1.9.0",
    "uninstall": "0.0.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.803.3",
    "@angular/cli": "~8.3.3",
    "@angular/compiler-cli": "~8.2.5",
    "@angular/language-service": "~8.2.5",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^8.9.5",
    "codelyzer": "^5.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.5.3"
  }
}

编辑:我发现了这个问题。 ../../../../../ 上的某个地方有一个流氓 node_modules 目录(显然在上面提到的错误日志中,但考虑到 npm 项目的嵌套性质,这似乎并不可疑)。 我不知道为什么或如何但是这个目录被扫描并抛出错误 - 这解释了为什么应用程序运行良好,因为我的项目中的 node_modules 目录很好。 我已经删除了这个流氓 node_modules 目录,现在错误消失了。

要检查的几件事:

  • 删除任何 package-lock.json 或 yarn-lock.json(通常当你有这个文件时你会安装旧版本,删除它可以让你有一个新安装的包)。

  • 运行npm cache clean --force

  • 删除 node_modules 文件夹。

  • 再次运行npm i

删除node_modules并尝试运行npm install

npm uninstall --save rxjs

然后试试这个:

npm install --save rxjs

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM