Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Can't resolve 'core-js/es7/reflect' in '\node_modules\@angular-devkit\build-angular\src\angular-cli-files\models

After updating to Angular 7.3.6, I get the following error on ng serve:

enter image description here

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 '\node_modules@angular-devkit\build-angular\src\angular-cli-files\models'

Here is my package.json dependecies:

{   "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"   } } 
like image 317
Bronsii Avatar asked Mar 28 '19 13:03

Bronsii


People also ask

How to resolve this issue with core-JS?

You can do that to resolve this issue: core-js Issue#412. and so on... In the version 3.0.0 of core-js, there are many changes, including in the path of some folders and files. Sorry, something went wrong. To fix this issue sooner, instead of upgrading to core-js@3 you just need to add core-js@2 to the dependencies of @angular-devkit/build-angular.

Is core-JS required for angular 8?

Angular CLI 8.0+ manages the required Angular polyfills directly and projects will not require a direct dependency on core-js (assuming an application does not manually include additional core-js polyfills). Sorry, something went wrong. Sorry, something went wrong.

Does angular CLI support node built-ins?

In Angular CLI we never provided a browser version of node built-ins. But we did: supply an empty module when fs, crypto, tls and net were requested. The Angular CLI team believes that libraries that are meant to run inside the browser are not supposed to use Node API –and I totally agree with them. Here is a quote from Filipe Silva.

How do I downgrade the core-JS version?

To resolve this error, you can downgrade the core-js version to 2.5.7. This version produces correct catalogs structure, with separate ES6 and ES7 folders. To downgrade the version, simply run: In my case, with Angular, this works ok.


2 Answers

You should install [email protected] that contains this file/module. See preset-env docs.

like image 171
nircraft Avatar answered Sep 19 '22 18:09

nircraft


If you'd like to use version 3.0, you can add the a path to your tsconfig.json file.

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

Note: You need check the node_modules/core-js/proposals/reflect-metadata relative path and correct it if needed in your project structure.

like image 30
Medeni Baykal Avatar answered Sep 22 '22 18:09

Medeni Baykal