【问题标题】:Multiple webpack in angular cli configuration角度 cli 配置中的多个 webpack
【发布时间】:2017-09-18 14:08:56
【问题描述】:

我正在尝试使用 karma 进行测试,但出现错误:

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 来自哪里?

【问题讨论】:

  • 答案就在您的眼前。这是 angular cli 的子依赖项。

标签: angular webpack angular-cli


【解决方案1】:

我已经多次看到这个问题。以前我只是偶然随机解决的。今天我才发现您看到此消息的原因是因为您的 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.

多多!!!!希望这会有所帮助!

【讨论】:

  • 感谢您的回答,这绝对是要走的路。与@alexKhymenko 的答案相同,但更详细
【解决方案2】:

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

【讨论】:

  • 这发生在我们所有人身上 :-) 没问题
  • 重新安装、删除 node_modules 文件夹、清除 npm 缓存等都没有解决。目前我正在使用 "@angular/cli": "^1.7.0" npm ls @ngtools/webpack 只显示一个 webpack ...错误是:Module build failed: Error: Angular Compiler was detected but it was an instance of the wrong class. This likely means you have several @ngtools/webpack packages installed.
【解决方案3】:

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

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

【讨论】:

    猜你喜欢
    • 2019-05-30
    • 1970-01-01
    • 2014-08-30
    • 2018-09-10
    • 2018-05-14
    • 2018-08-12
    • 1970-01-01
    • 2020-04-24
    • 2022-01-12
    相关资源
    最近更新 更多