Aji
Aji

Reputation: 474

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

I know this is already asked question i have tried all the possible things which i found there. Still am not able to crack it. Any help is appreciated.

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:\WORK\folder\folder\folder\node_modules\@ngtools\webpack\src\loader.js:33:15)
 @ multi ./src/main.ts
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:\WORK\folder\folder\folder\node_modules\@ngtools\webpack\src\loader.js:33:15)
 @ multi ./src/polyfills.ts
ERROR in Error: No NgModule metadata found for 'AppModule'.
    at NgModuleResolver.resolve (C:\WORK\folder\folder\folder\node_modules\@angular\compiler\bundles\compiler.umd.js:20291:23)
    at CompileMetadataResolver.getNgModuleMetadata (C:\WORK\folder\folder\folder\node_modules\@angular\compiler\bundles\compiler.umd.js:15244:60)
    at visitLazyRoute (C:\WORK\folder\folder\folder\node_modules\@angular\compiler\bundles\compiler.umd.js:31182:104)
    at AotCompiler.listLazyRoutes (C:\WORK\folder\folder\folder\node_modules\@angular\compiler\bundles\compiler.umd.js:31150:20)
    at AngularCompilerProgram.listLazyRoutes (C:\WORK\folder\folder\folder\node_modules\@angular\compiler-cli\src\transformers\program.js:228:34)
    at Function.NgTools_InternalApi_NG_2.listLazyRoutes (C:\WORK\folder\folder\folder\node_modules\@angular\compiler-cli\src\ngtools_api.js:47:40)
    at AngularCompilerPlugin._getLazyRoutesFromNgtools (C:\WORK\folder\folder\folder\node_modules\@angular\cli\node_modules\@ngtools\webpack\src\ang

Configuration:

Angular CLI: 1.7.0-beta.2
Node: 8.9.4
OS: win32 x64
Angular: 5.2.11
... animations, common, compiler, core, forms, http
... platform-browser, platform-browser-dynamic, router

@angular/cli: 1.7.0-beta.2
@angular/compiler-cli: 6.1.3
@angular/language-service: 6.1.3
@angular-devkit/architect: 0.8.0-beta.3
@angular-devkit/build-angular: 0.8.0-beta.3
@angular-devkit/build-optimizer: 0.8.0-beta.3
@angular-devkit/build-webpack: 0.8.0-beta.3
@angular-devkit/core: 0.8.0-beta.3
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 6.2.0-beta.3
@schematics/angular: 0.1.17
@schematics/package-update: 0.0.7
typescript: 2.9.2
webpack: 4.16.5

Package.json

{
  "name": "app1",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.9",
    "@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",
    "@progress/kendo-angular-buttons": "^3.0.4",
    "@progress/kendo-angular-dateinputs": "^2.2.0",
    "@progress/kendo-angular-dropdowns": "^2.1.0",
    "@progress/kendo-angular-excel-export": "^1.0.7",
    "@progress/kendo-angular-grid": "^2.1.2",
    "@progress/kendo-angular-inputs": "^2.2.0",
    "@progress/kendo-angular-intl": "^1.3.2",
    "@progress/kendo-angular-l10n": "^1.0.7",
    "@progress/kendo-data-query": "^1.2.0",
    "@progress/kendo-drawing": "^1.5.1",
    "@progress/kendo-ui": "^2018.2.620",
    "angular-font-awesome": "^3.1.2",
    "core-js": "^2.4.1",
    "font-awesome": "^4.7.0",
    "rxjs": "^5.5.6",
    "zone.js": "^0.8.19"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.8.0-beta.0",
    "@angular/cli": "1.7.0-beta.2",
    "@angular/compiler-cli": "^6.1.0",
    "@angular/language-service": "^6.1.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.3.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~1.7.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~2.9.2"
  }
}

npm list -global --depth 0

 +-- @angular/[email protected]
    +-- [email protected]
    +-- [email protected]
    +-- [email protected]
    +-- [email protected]
    +-- [email protected]
    +-- [email protected]
    +-- [email protected]
    `-- [email protected]

I have tried all the possible thinks like

any help here on what am missing will much appreciated am stuck here.

---------------------------------

After lots of research i was able to fix this issue by changing the package.json to below

{
  "name": "app1",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --prod",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^5.2.0",
    "@angular/cdk": "^5.2.4",
    "@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/material": "^5.2.4",
    "@angular/platform-browser": "^5.2.0",
    "@angular/platform-browser-dynamic": "^5.2.0",
    "@angular/router": "^5.2.0",
    "@progress/kendo-angular-buttons": "^3.0.4",
    "@progress/kendo-angular-dateinputs": "^2.2.0",
    "@progress/kendo-angular-dropdowns": "^2.1.0",
    "@progress/kendo-angular-excel-export": "^1.0.7",
    "@progress/kendo-angular-grid": "^2.1.2",
    "@progress/kendo-angular-inputs": "^2.2.0",
    "@progress/kendo-angular-intl": "^1.3.2",
    "@progress/kendo-angular-l10n": "^1.0.7",
    "@progress/kendo-data-query": "^1.2.0",
    "@progress/kendo-drawing": "^1.5.1",
    "@progress/kendo-ui": "^2018.2.620",
    "angular-font-awesome": "^3.1.2",
    "core-js": "^2.4.1",
    "ng2-tooltip": "0.0.7",
    "rxjs": "^5.5.6",
    "webpack": "^2.5.1",
    "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.5.3"
  }
}

but still there is one more issue which says.

ERROR in No NgModule metadata found for 'AppModule'.

Can any one please help here. any help is much appriciated

Upvotes: 9

Views: 6790

Answers (5)

Francesco Borzi
Francesco Borzi

Reputation: 61744

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

Upvotes: 4

Suvendu
Suvendu

Reputation: 455

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!

Upvotes: 2

Mahdi Shahbazi
Mahdi Shahbazi

Reputation: 1073

this one worked for me npm uninstall @angular-devkit/build-angular

npm install @angular-devkit/build-angular -D

Upvotes: 0

sree
sree

Reputation: 3193

I deleted the @ngtools\webpack folder and package-lock.json and then I run yarn (not npm install or npm update). I am not sure this is good fix, but it worked for me.

Upvotes: 0

hgiasac
hgiasac

Reputation: 2233

Your project's dependencies may be conflict. E.g @angular/compiler-cli version is 6.1.0 meanwhile @angular/core's version is still 5.20. Try to downgrade @angular/compiler-cli to 5.x or upgrade to angular 6 (https://update.angular.io/)

Upvotes: 0

Related Questions