@ngtools/webpack: Angular Compiler was detected but it was an instance of the wrong class.

1.1k views Asked by At

I already spent about 10 hours around this error:

ERROR in ./src/main.ts
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. You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies.    at Object.ngcLoader (C:\PRO\ANG\Cezar\CezarBot\Ajuro.Client\node_modules\@ngtools\webpack\src\loader.js:33:15)
ERROR in ./src/polyfills.ts
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. You can check this with `npm ls @ngtools/webpack`, and then remove the extra copies.    at Object.ngcLoader (C:\PRO\ANG\Cezar\CezarBot\Ajuro.Client\node_modules\@ngtools\webpack\src\loader.js:33:15)

I added image because is easier to be recognized. In my attempts to solve it I updated node, I reinstalled webpack, I reinstalled @angular/cli, @ngtools/webpack, cleared the cache with --force, run npm install. I also reinstalled the global @angular/cli.

At some points I ended up with one or no @ngtools/webpack versions in local node-modules or in %appdata%/npm. The error was the same.

enter image description here

I think it is not related to @ngtools/webpack How can I investigate?

1

There are 1 answers

0
profimedica On

I will not mark my answer as accepted. But here is the result of my investigation:

The error was caused by undefined angular_compiler_plugin_1.AngularCompilerPlugin in Loader.js, as I found using a simple JSON.Stringify(...). This might be caused by a recent removing of decorators. Instead of downgrading modules, I continued with all I have.

I commented the condition for failre in Loader.js:32 so that I can find the real cause:

/* if (!(plugin instanceof angular_compiler_plugin_1.AngularCompilerPlugin) || !plugin.done) { .... */

The second error was

Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 10.x

So, I uninstalled node-sass module because I did not really needed it

The project works fine now (with this temporary work-around) until I find a proper solution.