角度cli配置中的多个webpack

时间:2017-09-18 14:08:57

标签: angular webpack angular-cli

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

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.

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

+-- @angular/cli@1.1.1
| `-- @ngtools/webpack@1.4.1
`-- @ngtools/webpack@1.5.1

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

这1.4.1来自哪里?

3 个答案:

答案 0 :(得分:7)

我已多次看过这个问题。以前我只是偶然随机解决了。今天我只是想通了你看到这条消息的原因是因为你的package.json中“devDependencies”中的@ angular / cli版本与你的依赖版本不匹配。例如,在我运行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.

多田!!!!希望这有帮助!

答案 1 :(得分:4)

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

答案 2 :(得分:0)

要将其从package.json中的依赖项中删除,您将需要使用save标志:

npm uninstall --save webpack

如果您已将软件包安装为“ devDependency”(即使用--save-dev),则--save不会将其从package.json中删除。您需要使用--save-dev来卸载它。 这是上面命令的结果

$ npm ls @ngtools/webpack
angularapp@0.0.0 C:\Apache24\htdocs\angularapp
+-- @angular-devkit/build-angular@0.7.5
| `-- @ngtools/webpack@6.1.5
`-- @ngtools/webpack@6.2.1

$ npm uninstall --save webpack
> node-sass@4.9.3 install C:\Apache24\htdocs\angularapp\node_modules\node-sass
> node scripts/install.js

Cached binary found at C:\Users\user\AppData\Roaming\npm-cache\node-sass\4.9.3\win32-x64-59_binding.node

> node-sass@4.9.3 postinstall C:\Apache24\htdocs\angularapp\node_modules\node-sass
> node scripts/build.js

Binary found at C:\Apache24\htdocs\angularapp\node_modules\node-sass\vendor\win32-x64-59\binding.node
Testing binary
Binary is fine
added 1106 packages in 677.641s

$ npm ls @ngtools/webpack
angularapp@0.0.0 C:\Apache24\htdocs\angularapp
`-- @angular-devkit/build-angular@0.7.5
  `-- @ngtools/webpack@6.1.5