4
votes
Global Angular CLI: 7.3.8
Node v10.15.3
NPM 6.4.1
macos

I'm getting this error on npm start

ERROR in ./node_modules/@angular-devkit/build-angular/src/angular-cli-files/models/jit-polyfills.js Module not found: Error: Can't resolve 'core-js/es7/reflect' in '/Users/XXX/projects/XXX/node_modules/@angular-devkit/build-angular/src/angular-cli-files/models' ERROR in ./src/polyfills.ts Module not found: Error: Can't resolve 'core-js/es7/reflect' in '/Users/XXX/projects/XXX/src'

5
For projects being upgraded to Angular 8 or later, you can uninstall core.js as a dependency: stackoverflow.com/questions/56892243/…John Gilmer
@JohnGilmer Thank you for your comment. Feel free to add it as an answer. It will be helpfulDmitry Grinko

5 Answers

16
votes

To solve this issue I've added the following paths to compilerOptions in tsconfig.json

{
  "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"
    ]
  }
}
4
votes

After Migrated to new Angular version, 'core-js/es6' or 'core-js/es7' Will not work.

You have to simply replace import 'core-js/es/'

For ex. import 'core-js/es6/symbol' to import 'core-js/es/symbol'

This will work properly.

1
votes

just remove the number at the end of 'es' in the path, like 'core-js/es/reflect'. It worked for me.

0
votes

I just copy all from my oldest project src/polyfills to the new imported. That's help ;) .

0
votes

Getting this error in "@angular/cli": "~10.1.5" project:

Cannot find module 'core-js/es7/reflect' or its corresponding type declarations.ts(2307)

Solution:

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