1

In a process of migration from webpack2 to webpack4 and from Angular4 to Angular5 I'm getting strange error for webpack compilation (./node_modules/.bin/webpack-cli):

ERROR in Could not resolve module @angular/core

Debugging webpack (node --inspect-brk ./node_modules/.bin/webpack-cli) got an error stack trace:

Error: Could not resolve module @angular/core
    at StaticSymbolResolver.getSymbolByModule (.../node_modules/@angular/compiler/bundles/compiler.umd.js:29766:30)
    at StaticReflector.findDeclaration (.../node_modules/@angular/compiler/bundles/compiler.umd.js:31635:63)
    at StaticReflector.initializeConversionMap (.../node_modules/@angular/compiler/bundles/compiler.umd.js:31953:36)
    at new StaticReflector (.../node_modules/@angular/compiler/bundles/compiler.umd.js:31571:14)
    at Object.createAotCompiler (.../node_modules/@angular/compiler/bundles/compiler.umd.js:32957:44)
    at AngularCompilerProgram._createCompiler (.../node_modules/@angular/compiler-cli/src/transformers/program.js:404:37)
    at AngularCompilerProgram.get [as hostAdapter] (.../node_modules/@angular/compiler-cli/src/transformers/program.js:327:22)
    at AngularCompilerProgram._createProgramWithBasicStubs (.../node_modules/@angular/compiler-cli/src/transformers/program.js:435:73)
    at .../node_modules/@angular/compiler-cli/src/transformers/program.js:143:28
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
    at Function.Module.runMain (module.js:684:11)
    at startup (bootstrap_node.js:191:16)
    at bootstrap_node.js:613:3

But unfortunately it still does not give a hint.

Here is package.json dependancies.

Reported this issue on angular repo.

Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176

2 Answers2

0

I fact installing module @angular-devkit/core solved the problem

Stepan Suvorov
  • 25,118
  • 26
  • 108
  • 176
0

Just ran into this today using Angular 10. This message continued even after a clean install

npm ci
ng build
ERROR in Could not resolve module @angular/core

We were working on a library install at the time, updating the library and installing new versions each new update. The root cause of this issue was that an NPM Uninstall of that library somehow didn't tell webpack the information. (or perhaps we just removed the lib entry in package.json). Thus the build failure wasn't really @angular/core it was that web pack could not find our library to install.

The fix: We re-installed our library again.

npm install libName // which put a new entry into package.json

It's a known fact that webpack error messages are the worst, they tell us nothing as to who, where or why... How do we know this was a web-pack compile time error message?

Generating ES5 bundles for differential loading...  
JWP
  • 6,672
  • 3
  • 50
  • 74