角度cli配置中的多个webpack

An-*_*oid 5 webpack angular-cli angular

我试图用业力做测试,但得到一个错误:

ERROR in ./src/test.ts
Module build failed: Error: AotPlugin was detected but it was an instance of the wrong class.
This likely means you have several @ngtools/webpack packages installed. You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies.
Run Code Online (Sandbox Code Playgroud)

当我执行cmd时,我得到了这个结果:

+-- @angular/cli@1.1.1
| `-- @ngtools/webpack@1.4.1
`-- @ngtools/webpack@1.5.1
Run Code Online (Sandbox Code Playgroud)

在我,package.json我只有@ngtools/webpack": "^1.5.1

1.4.1来自哪里?

小智 8

我已多次看过这个问题了.以前我只是偶然随机解决了.而今天我只是想通了,为什么你看到这个消息的原因是因为@角/ CLI的版本,在"devDependencies"在你的package.json不会与你的依赖版本相匹配.例如,在我运行之后npm ls @ngtools/webpack,我看到以下内容: atom-web-accessibility@1.0.0 /Users/jma/atom-web-accessibility ??? @abot/atom-web-higgs@3.16.1 ? ??? @angular/cli@1.4.7 ? ??? @ngtools/webpack@1.7.4 ??? @angular/cli@1.7.3 ??? @ngtools/webpack@1.10.2

所以,现在我必须去我的package.json下"devDependencies",更改版本号"1.7.3""1.4.7".然后运行以下命令: rm -rf node_modules

rm -rf package-lock.json

npm cache clean -f

npm install

ng build

npm start

然后我明白了 webpack: Compiled successfully.

田田!!!! 希望这可以帮助!


ale*_*nko 4

它来自 Angular cli。从 json 包中删除你的。重新安装模块。它会起作用的。