【问题标题】:Migration from Angular 6 to Angular 7 cause error - Can't resolve 'core-js/es7/reflect'从 Angular 6 迁移到 Angular 7 导致错误 - 无法解析“core-js/es7/reflect”
【发布时间】:2019-09-09 04:30:58
【问题描述】:
Global Angular CLI: 7.3.8
Node v10.15.3
NPM 6.4.1
macos

我在npm start 收到此错误

错误 ./node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/jit-polyfills.js 找不到模块:错误:无法解析“core-js/es7/reflect” '/Users/XXX/projects/XXX/node_modules/@angular-devkit/build-angular/src/angular-cli-files/models' ./src/polyfills.ts 中的错误找不到模块:错误:无法解析 '/Users/XXX/projects/XXX/src'中的'core-js/es7/reflect'

【问题讨论】:

  • 对于升级到 Angular 8 或更高版本的项目,您可以将 core.js 作为依赖项卸载:stackoverflow.com/questions/56892243/…
  • @JohnGilmer 感谢您的评论。随意添加它作为答案。会有帮助的

标签: node.js angular npm


【解决方案1】:

为了解决这个问题,我在 tsconfig.json 中为 compilerOptions 添加了以下路径

{
  "compileOnSave": false,
  "compilerOptions": {
    "paths": {
      "core-js/es7/reflect": [
        "node_modules/core-js/proposals/reflect-metadata",
      ],
      "core-js/es6/*": ["node_modules/core-js/es"]
    },
    "baseUrl": "./",
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es5",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2017",
      "dom"
    ]
  }
}

【讨论】:

  • 你是一个救生员。这也是我所需要的。
【解决方案2】:

迁移到新的 Angular 版本后,'core-js/es6' 或 'core-js/es7' 将不起作用。

你必须简单地替换 import 'core-js/es/'

例如。导入 'core-js/es6/symbol' 来导入 'core-js/es/symbol'

这将正常工作。

【讨论】:

    【解决方案3】:

    我只是将我最旧的项目src/polyfills 中的所有内容复制到新导入的项目中。这很有帮助;)。

    【讨论】:

      【解决方案4】:

      只需删除路径中“es”末尾的数字,例如“core-js/es/reflect”。它对我有用。

      【讨论】:

        【解决方案5】:

        "@angular/cli": "~10.1.5" 项目中出现此错误:

        找不到模块'core-js/es7/reflect'或其对应的类型声明.ts(2307)

        解决方案:

        import * as Reflect from 'core-js/es';
        

        【讨论】:

          猜你喜欢
          • 2019-08-19
          • 2019-03-26
          • 2018-10-18
          • 2020-06-15
          • 2017-01-29
          • 2020-05-08
          • 2020-02-24
          • 2018-04-23
          • 1970-01-01
          相关资源
          最近更新 更多