1

在从 webpack2 迁移到webpack4以及从 Angular4迁移到Angular5的过程中,我遇到了 webpack 编译的奇怪错误(./node_modules/.bin/webpack-cli):

无法解析模块 @angular/core 中的错误

调试 webpack ( node --inspect-brk ./node_modules/.bin/webpack-cli) 得到错误堆栈跟踪:

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

但不幸的是,它仍然没有给出提示。

这是package.json 依赖项

在 angular repo上报告了这个问题。

4

2 回答 2

0

我实际上安装模块@angular-devkit/core解决了这个问题

于 2018-04-04T16:44:07.170 回答
0

今天刚刚使用 Angular 10 遇到了这个问题。即使在全新安装之后,此消息仍在继续

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

我们当时正在安装库,更新库并在每次新更新时安装新版本。这个问题的根本原因是该库的 NPM 卸载不知何故没有告诉 webpack 信息。(或者也许我们只是删除了 package.json 中的 lib 条目)。因此,构建失败并不是真正的@angular/core,而是 web pack 找不到我们要安装的库。

修复:我们再次重新安装了我们的库。

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

众所周知,webpack 错误消息是最糟糕的,它们没有告诉我们谁、在哪里或为什么......我们怎么知道这是一个 web-pack 编译时错误消息?

Generating ES5 bundles for differential loading...  
于 2020-07-10T17:53:21.737 回答