angular-cli: Angular Compiler Error (seems to be the wrong instance)
when I try to run “ng serve” I run into the following issue:
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.
Following this suggestion:
$ npm ls
@ngtools/webpacktest@0.0.0 C:\Daten\Projects\test-- @angular/cli@1.7.2– @ngtools/webpack@1.10.1
So there are no multiple webpack versions installed. I tried to reinstall @angular/cli for multiple times…globally, locally, after deleting node_modules and using npm cache clean -f and npm cache verify. I did the same with webpack. Sadly there are not really many other people running into this issue, what makes it hard to solve. My google researches were not successfull due to all i could found was a chinese page translating that error into chinese and these two SO links (which do not provide a solution for me):
https://stackoverflow.com/search?q=Angular+Compiler+was+detected
https://stackoverflow.com/questions/48774405/error-several-ngtools-webpack-packages-installed
my package.json:
"dependencies": {
"@angular/animations": "^5.2.0",
"@angular/common": "^5.2.0",
"@angular/compiler": "^5.2.0",
"@angular/core": "^5.2.0",
"@angular/forms": "^5.2.0",
"@angular/http": "^5.2.0",
"@angular/platform-browser": "^5.2.0",
"@angular/platform-browser-dynamic": "^5.2.0",
"@angular/router": "^5.2.0",
"core-js": "^2.4.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"@angular/cli": "^1.7.2",
"@angular/compiler-cli": "^5.2.0",
"@angular/language-service": "^5.2.0",
"@types/jasmine": "~2.8.3",
"@types/jasminewd2": "~2.0.2",
"@types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "2.6.2"
}
}
note:
The project can be compiled at my brothers PC - the only difference is the OS (he uses win7 while i use win10).
greetings and have a nice week end,
Messerbill
edit:
Updating @angular to 5.2.7 makes no difference.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 3
- Comments: 22 (1 by maintainers)
Since I have had this error multiple times (I have 3 libraries and 4 apps in a mono-repo, quite like
@angular/*. I figured out the error in the first 2 libraries and forgot to fix it in the last library and had to figure it out all over again. For future reference for others (and in case I forget again), my fix was to make sure that@angular-devkit/build-angularand@angular-devkit/build-ng-packagrare only in the root package.json. For example, if I had the following structure:So to fix this, I needed to remove @angular-devkit from my libraries like so:
yarn remove @angular-devkit/build-angular && yarn remove @angular/build-ng-packagrpackage.jsonyarn.lockfile after removal (3 & 4 should be automatic)Finally. Updating my global
typescriptversion fixed it. Now using tsc2.6.2globally and it works.The full command suggestion is actually
npm ls @ngtools/webpack. The error is due to multiple versions of the@ngtools/webpackpackage being present in the project. You can try deleting both thepackage-lock.jsonfile and thenode_modulesfolder and then install again.Worked for me, thanks.
Hi, thanks for your answer.
npm ls @ngtools/webpackis exactly what i did (as i wrote in my question).this is what i tried hundrets of times
no - my
npm ls @ngtools/webpackdoes NOT return multiple versions.edit
sorry, due to the markup the full
npm ls @ngtools/webpackwas not visiblenpm ls -galso shows no webpack installed globallyedit edit:
ng serveandng builddoes not make any differences:(due to the bad screenshot you cannot see completley, that the global ls is just the same like the local. But if i remove the global, my
ngcommand is not found anymore.