【问题标题】:Upgrade angular 7 to 8 successful, but core can't find module rxjs?将angular 7升级到8成功,但是core找不到模块rxjs?
【发布时间】:2020-01-10 07:10:48
【问题描述】:

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

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

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"
  }
}

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

【问题讨论】:

  • 在运行npm install之前,您是否尝试过删除node_modules
  • @jpavel 删除 node_modules 并重新安装 npm 解决了我遇到的一些随机其他(不相关)警告,但此错误仍然存​​在。
  • 我已经将我的一个项目(只是为了测试)升级到您在帖子中提到的版本,没有任何问题。 ng --version 有什么用?
  • 你检查node_modules中是否有rxjs文件夹吗?
  • 我发现了问题。在 ../../../../../ 的某个地方有一个 rogue node_modules 目录(这在上面提到的错误日志中很明显,但考虑到 npm 项目的嵌套性质,这似乎并不可疑)。我不知道为什么或如何,但这个目录被扫描并吐出错误 - 这解释了为什么应用程序运行良好。

标签: angular typescript ecmascript-6 rxjs single-page-application


【解决方案1】:

几件事要检查:

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

  • 运行npm cache clean --force

  • 删除 node_modules 文件夹。

  • 再次运行npm i

【讨论】:

  • 完全按照这些步骤,结果是一样的。我发现 rxjs-compat 丢失了,但是添加该包也没有解决这个问题。
【解决方案2】:

删除node_modules 并尝试运行npm install

npm uninstall --save rxjs

然后试试这个:

npm install --save rxjs

【讨论】:

  • 删除 node_modules 并重新安装 npm 解决了我遇到的其他一些随机(不相关)警告,但此错误仍然存​​在。
  • @user1884155 查看更改。
  • 嗯,这个没有做任何事情。我卸载了rxjs 6.3.5,然后重新安装了它,但错误仍然存​​在。
猜你喜欢
  • 2019-07-12
  • 2020-06-23
  • 2019-02-15
  • 1970-01-01
  • 2021-08-28
  • 1970-01-01
  • 2021-05-08
  • 1970-01-01
  • 2019-11-24
相关资源
最近更新 更多