简体   繁体   English

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

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

I upgraded angular 7.X to angular 8.2.5.我将 angular 7.X 升级到了 angular 8.2.5。 This is successful, and my application still runs.这是成功的,我的应用程序仍在运行。 However, the angular/core module throws errors, claiming it cannot find rxjs .然而, angular/core模块抛出错误,声称它找不到rxjs My version of rxjs is 6.5.3, which is brand new as of this writing.I have uninstalled rxjs-compat and reran npm install but the behavior did not change.我的rxjs版本是 6.5.3,在rxjs是全新的。我已经卸载了rxjs-compat并重新运行npm install但行为没有改变。

ngserve 上的错误

(Text version for google searches:) (谷歌搜索的文本版本:)

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';

Subsequent compiles yield a similar but more compact error.后续编译会产生类似但更紧凑的错误。 For now, this does not seem to impact my application, it still runs.目前,这似乎不会影响我的应用程序,它仍在运行。

在此处输入图片说明

What actions can I try to get rid of this error?我可以尝试哪些操作来消除此错误?

Package.json:包.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"
  }
}

EDIT: I found the issue.编辑:我发现了这个问题。 There was rogue node_modules directory somewhere on ../../../../../ (which was clearly in the error logs mentioned above, but didn't seem suspicious considering the nested nature of npm projects). ../../../../../ 上的某个地方有一个流氓 node_modules 目录(显然在上面提到的错误日志中,但考虑到 npm 项目的嵌套性质,这似乎并不可疑)。 I don't know why or how but this directory was scanned and spewed errors - this explains why the app was running fine, because the node_modules directory in my project was just fine.我不知道为什么或如何但是这个目录被扫描并抛出错误 - 这解释了为什么应用程序运行良好,因为我的项目中的 node_modules 目录很好。 I have deleted this rogue node_modules directory and the errors are now gone.我已经删除了这个流氓 node_modules 目录,现在错误消失了。

Few thing to check:要检查的几件事:

  • Delete any package-lock.json or yarn-lock.json (Normally you install old version when you have this file, deleting it allows you to have a freshly installed package).删除任何 package-lock.json 或 yarn-lock.json(通常当你有这个文件时你会安装旧版本,删除它可以让你有一个新安装的包)。

  • Run npm cache clean --force .运行npm cache clean --force

  • Delete node_modules folder.删除 node_modules 文件夹。

  • Run npm i again.再次运行npm i

Delete the node_modules and try to run npm install .删除node_modules并尝试运行npm install

npm uninstall --save rxjs

Then try this:然后试试这个:

npm install --save rxjs

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

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