angularjs - 错误 : AotPlugin was detected but it was an instance of the wrong class

标签 angularjs node.js

问题

ng serve

Module build failed: Error: AotPlugin was detected but it was an instance of the wrong class.

完整的错误报告日志

  ERROR in ./src/main.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.
  at Object.ngcLoader 
 (D:\testingapp\node_modules\@ngtools\webpack\src\loader.js:358:19)
  @ multi webpack-dev-server/client?http://localhost:4200 ./src/main.ts

npm ls @ngtools/webpack

testingapp@0.0.0 D:\testingapp
 +-- @angular/cli@1.2.6
 | `-- @ngtools/webpack@1.5.5
`-- angular-cli@1.0.0-beta.28.3
 `-- @ngtools/webpack@1.5.1

npm cache verify

问题依然存在

欢迎提出任何建议。

最佳答案

在运行 ng eject 并尝试运行我的业力测试后,我遇到了这个问题。

尽管我认为这不是最佳解决方案,但我通过以下方式解决了这个问题:

  1. 删除 @ngtools/webpack

    $ npm remove --save @ngtools/webpack

  2. 在我的 webpack.config.js 中要求 @ngtools/webpack@angular/cli 的子依赖

    // webpack.config.js
       //
     // Other require statements
     const { AotPlugin } = 
    require('./node_modules/@angular/cli/node_modules/@ngtools/webpack');
    /* 
    * Change the loader 
    /* 
    
      module.exports = {
        // ...
    
         "module": {
        "rules": {
         // ...
          {
          "test": /\.ts$/,
          /* REMOVE: "loader": "@ngtools/webpack", */
          "loader": 
            "./node_modules/@angular/cli/node_modules/@ngtools/webpack"
              }
         }
         // ...
         }
         }
    

关于angularjs - 错误 : AotPlugin was detected but it was an instance of the wrong class,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45409582/

相关文章:

mysql - 如何使用 npm mysql 将表达式与批量插入结合使用?

angularjs - 如何使用 oauth2 登录重定向到 Angular 路由器链接?

angularjs - 在 WebStorm 中运行 AngularJS 应用程序

javascript - ng-repeat 过滤器 - 没有过滤对吗?

node.js - 在 Mac OS : "Connection refused! Is selenium server started?" 上使用 Nightwatchjs 在 Chrome 中启动测试

javascript - 遗漏或尝试后终于

java - Angular 2 : Install external library using npm through Maven

javascript - 页面刷新时的 Angular 'Cannot GET' 路由

javascript - 如何使用 Angular.js 添加裁剪图像

javascript - Angularjs ng-Grid注入(inject)错误