ERROR出错:AppModule不是NgModule - Angular-cli

时间:2017-12-12 09:59:08

标签: node.js angular npm angular-cli

我正在使用带角度cli的Angular 4进行Web应用程序。从上周开始,我开始收到以下错误,我正在尝试修复:

错误中的

错误:AppModule不是NgModule     at _getNgModuleMetadata(D:.Net Projects \ Angular 2 \ engineUI \ node_modules \ @angular \ compiler-cli \ src \ ngtools_impl.js:140:15)     at _extractLazyRoutesFromStaticModule(D:.Net Projects \ Angular 2 \ engineUI \ node_modules \ @angular \ compiler-cli \ src \ ngtools_impl.js:109:26)     at Object.listLazyRoutesOfModule(D:.Net Projects \ Angular 2 \ engineUI \ node_modules \ @angular \ compiler-cli \ src \ ngtools_impl.js:53:22)     在Function.NgTools_InternalApi_NG_2.listLazyRoutes(D:.Net Projects \ Angular 2 \ engineUI \ node_modules \ @angular \ compiler-cli \ src \ ngtools_api.js:91:39)     在AotPlugin._getLazyRoutesFromNgtools(D:.Net Projects \ Angular 2 \ engineUI \ node_modules \ @angular \ cli \ node_modules \ @ngtools \ webpack \ src \ plugin.js:241:66)     在_donePromise.Promise.resolve.then.then.then.then.then(D:.Net Projects \ Angular 2 \ engineUI \ node_modules \ @angular \ cli \ node_modules \ @ngtools \ webpack \ src \ plugin.js:4 95:24)     在

我尝试了各种选项,例如以管理员身份运行,清理NPM缓存,但我仍然在ng build命令上收到此错误。

我的节点版本是:v8.9.1 NPM版本:5.6.0 Angular-cli:1.6.0

package.json文件:

{
"name": "recommendation-engine",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^4.2.4",
"@angular/cdk": "^2.0.0-beta.12",
"@angular/common": "^4.2.4",
"@angular/compiler": "^4.2.4",
"@angular/core": "^4.2.4",
"@angular/forms": "^4.2.4",
"@angular/http": "^4.2.4",
"@angular/material": "^2.0.0-beta.12",
"@angular/platform-browser": "^4.2.4",
"@angular/platform-browser-dynamic": "^4.2.4",
"@angular/router": "^4.2.4",
"@types/lodash": "^4.14.85",
"angular2-highlight-js": "^5.0.0",
"core-js": "^2.4.1",
"hammerjs": "^2.0.8",
"lodash": "^4.17.4",
"ngx-loading": "^1.0.8",
"ngx-slick": "^0.1.3",
"rxjs": "^5.4.2",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.5.2",
"@angular/compiler-cli": "^4.2.4",
"@angular/language-service": "^4.2.4",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.92",
"codelyzer": "~3.2.0",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"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": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "~2.3.3"
}
}

.angular-cli.json文件

{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "engine"
},
"apps": [
{
  "root": "src",
  "outDir": "dist",
  "assets": [
    "assets",
    "favicon.ico"
  ],
  "index": "index.html",
  "main": "main.ts",
  "polyfills": "polyfills.ts",
  "test": "test.ts",
  "tsconfig": "tsconfig.app.json",
  "testTsconfig": "tsconfig.spec.json",
  "prefix": "app",
  "styles": [
    "styles.css"
  ],
  "scripts": [],
  "environmentSource": "environments/environment.ts",
  "environments": {
    "dev": "environments/environment.ts",
    "prod": "environments/environment.prod.ts"
  }
}
],
"e2e": {
"protractor": {
  "config": "./protractor.conf.js"
}
},
"lint": [
{
  "project": "src/tsconfig.app.json",
  "exclude": "**/node_modules/**"
},
{
  "project": "src/tsconfig.spec.json",
  "exclude": "**/node_modules/**"
},
{
  "project": "e2e/tsconfig.e2e.json",
  "exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
  "config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}

有人可以帮我解决这个问题吗?

1 个答案:

答案 0 :(得分:2)

更新后我遇到了这个问题。然后我删除了node_modules文件夹和package-lock.json ,然后做了一个干净的

npm install

在我的案例中,罪魁祸首确实是package-lock.json。当多个人在项目上工作并且没有签入此文件时,情况会变得更糟!