Angular Compiler was detected but it was an instance of the wrong class

I had the same issue and resolved by:

1) updating the package @ngtools/webpack to the latest version

2) deleting node_modules, package-lock.json and running a clean npm install


This one seems to be the best solution and worked twice for me. Run the following command -

npm dedupe

You will be able to see some auditing detail. To fix just run -

npm audit fix

and if necessary (the error persists), run following -

npm audit fix --force

This will dedupe all the duplicate packages along with fixing their versions numbers as well.

Hope this helps!