错误:无法解析' node_modules @ angular-devkit build-angular src angular-cli-files models中的&#

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了错误:无法解析' node_modules @ angular-devkit build-angular src angular-cli-files models中的&#相关的知识,希望对你有一定的参考价值。

更新到Angular 7.3.6后,我在ng服务上收到以下错误:

enter image description here

错误:./node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/jit-polyfills.js找不到模块:错误:无法解析'core-js / es7 / reflect'in '\ node_modules @角的devkit \集结角的\ src \角CLI-文件\车型'

这是我的package.json依赖项:


  "name": "frontend",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": 
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  ,
  "private": true,
  "dependencies": 
    "@angular/animations": "^7.2.11",
    "@angular/cdk": "^7.3.6",
    "@angular/common": "^7.2.11",
    "@angular/compiler": "^7.2.11",
    "@angular/core": "^7.2.11",
    "@angular/flex-layout": "^7.0.0-beta.24",
    "@angular/forms": "^7.2.11",
    "@angular/http": "^7.2.11",
    "@angular/material": "^7.3.6",
    "@angular/platform-browser": "^7.2.11",
    "@angular/platform-browser-dynamic": "^7.2.11",
    "@angular/router": "^7.2.11",
    "adm-zip": "^0.4.13",
    "core-js": "^2.6.5",
    "hammerjs": "^2.0.8",
    "rxjs": "^6.4.0",
    "rxjs-compat": "^6.0.0-rc.0",
    "tslib": "^1.9.3",
    "zone.js": "^0.9.0"
  ,
  "devDependencies": 
    "@angular-devkit/build-angular": "^0.13.7",
    "@angular/cli": "^7.3.7",
    "@angular/compiler-cli": "^7.2.11",
    "@angular/language-service": "^7.2.11",
    "@types/jasmine": "~3.3.12",
    "@types/jasminewd2": "~2.0.6",
    "@types/node": "~11.12.0",
    "codelyzer": "^5.0.0",
    "jasmine-core": "~3.3.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "^4.0.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "^2.0.5",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "^6.0.0",
    "ts-node": "~8.0.3",
    "tslint": "~5.14.0",
    "typescript": "3.1.6"
  

答案

您应该安装包含此文件/模块的core-js@2.5.x。见preset-env docs

另一答案

core-js的3.0版本有一些重大变化:

https://github.com/zloirock/core-js/blob/master/docs/2019-03-19-core-js-3-babel-and-a-look-into-the-future.md

您应该在一个文件中找到与此类似的行:import "core-js/es7/reflect";

改为:import "core-js/proposals/reflect-metadata";

另一答案

如果您想使用3.0版,可以添加tsconfig.json文件的路径。


    "compilerOptions": 
        ...
        "paths": 
            "core-js/es7/reflect": [
                "node_modules/core-js/proposals/reflect-metadata"
            ]
        
    

另一答案

我找到了可能的答案。你有core-js 3.0版,这个版本没有ES6和ES7的单独文件夹;这就是应用程序无法找到正确路径的原因。

要解决此错误,可以将core-js版本降级到2.5.7。此版本生成正确的目录结构,具有单独的ES6和ES7文件夹。

要降级版本,只需运行:

npm和-S core-js@2.5.7

以上是关于错误:无法解析' node_modules @ angular-devkit build-angular src angular-cli-files models中的&#的主要内容,如果未能解决你的问题,请参考以下文章

在Angular 7中使用SJCL时无法解析'./node_modules/sjcl'中的'crypto']

找不到模块:错误:无法解析“/app/node_modules/next/dist/lib”中的“pnpapi”

错误 - ./node_modules/busboy/lib/main.js:1:0 找不到模块:无法解析“fs”

错误:错误:无法从 /node_modules/react-native-reanimated/src/reanimated2/index.ts 解析模块./Hooks

错误:找不到模块:无法解析“/home/rakesh95/Projects/webapp/node_modules/quickblox/src/modules/chat”中的“nativescript

错误:无法解析 '\node_modules\@angular-devkit\build-angular\src\angular-cli-files\models 中的 'core-js/es7/re