angular-cli: ERROR in AppModule is not an NgModule

Please provide us with the following information:

OS?

Windows 7

Versions.

ng --version @angular/cli: 1.0.0-beta.31 node: 7.2.0 os: win32 x64 @angular/common: 2.4.7 @angular/compiler: 2.4.7 @angular/core: 2.4.7 @angular/forms: 2.4.7 @angular/http: 2.4.7 @angular/platform-browser: 2.4.7 @angular/platform-browser-dynamic: 2.4.7 @angular/router: 3.4.7 @angular/cli: 1.0.0-beta.31 @angular/compiler-cli: 2.4.7 @ngtools/webpack: 1.2.9

$ npm list -g --depth=0 C:\Users\Macpro\AppData\Roaming\npm ±- @angular/cli@1.0.0-beta.31 ±- cordova@6.5.0 ±- grunt-cli@1.2.0 ±- http-server@0.9.0 ±- ionic@2.2.1 ±- minimatch@3.0.3 ±- node-uuid@1.4.7 ±- npm@4.2.0 `-- typescript@2.1.6

Repro steps.

I’ve tried to update the angular-cli with these steps: https://github.com/angular/angular-cli#updating-angular-cli

I’ve done global update and local project as well, all good until I try to serve the app - it gives me the below error

The log given by the failure.

$ ng serve

ERROR in AppModule is not an NgModule ERROR in ./src/main.ts Module build failed: TypeError: Cannot read property ‘newLine’ of undefined at Object.getNewLineCharacter (C:\Users\Macpro\Desktop\Test\Angular2\Angular2\CLI\puzzleTest\node_modules\typescript\lib\typescript.js:8062:20) at Object.createCompilerHost (C:\Users\Macpro\Desktop\Test\Angular2\Angular2\CLI\puzzleTest\node_modules\typescript\lib\typescript.js:44978:26) at Object.ngcLoader (C:\Users\Macpro\Desktop\Test\Angular2\Angular2\CLI\puzzleTest\node_modules@ngtools\webpack\src\loader.js:341:33) @ multi webpack-dev-server/client?http://localhost:4200/ ./src/main.ts webpack: Failed to compile.


I also got this “minimatch” errror every time I try to update or install somtehing: npm update -g

npm WARN deprecated minimatch@0.2.14: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

But as you can see above I have “minimatch@3.0.3” - anyway this is not the problem here

Mention any other details that might be useful.

I’ve tried to update the typescript like I’ve seen on the web but with no success. I also


Thank you for your time!

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 12
  • Comments: 43 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I got the same problem. On ubuntu 16. But only on the first build: image The only change I made was adding an empty line to the app.module.ts

Don’t ask me why, but I think this is a yarn issue. Running

rm -rf node_modules
npm i
ng serve

fixes the problem, but the problem remains if you do yarn instead of npm i.

EDIT: another thing that worked was reinstalling yarn : https://yarnpkg.com/lang/en/docs/install/#linux-tab

I ran into this same issue, and I don’t use yarn. Here is the only way it fixed it for me:

rm -rf node_modules package-lock.json
npm install 
ng s 

@tHesTx, no, just use npm install instead. For me, the problem occurs when I use yarn instead. It is solved if I use npm. Also, in my case it was just on the first run, after that it worked ok.

Still happening for us with npm. Using angular version 4.2.6 and angular material with typescript 2.2.3 (also tried 2.3 and 2.4).

I am seeing this error when I install using yarn after upgrading to "@angular/cli": "^1.0.0-rc.4".

I don’t not see this problem if I do npm install, only when I install using yarn.

Also I have deleted node_modules folder and my yarn.lock file.

Here is my package.json file.

{
  "name": "routes",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update --standalone false --gecko false",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "^2.4.10",
    "@angular/compiler": "^2.4.10",
    "@angular/core": "^2.4.10",
    "@angular/forms": "^2.4.10",
    "@angular/http": "^2.4.10",
    "@angular/platform-browser": "^2.4.10",
    "@angular/platform-browser-dynamic": "^2.4.10",
    "@angular/router": "^3.4.10",
    "@types/node": "^6.0.65",
    "codelyzer": "^2.0.1",
    "core-js": "^2.4.1",
    "rxjs": "^5.2.0",
    "ts-helpers": "^1.1.2",
    "tslint": "^4.5.1",
    "zone.js": "^0.7.8"
  },
  "devDependencies": {
    "@angular/cli": "^1.0.0-rc.4",
    "@angular/compiler-cli": "^2.4.10",
    "@types/jasmine": "^2.5.46",
    "@types/node": "^6.0.65",
    "codelyzer": "^2.0.1",
    "jasmine-core": "^2.5.2",
    "jasmine-spec-reporter": "^2.7.0",
    "karma": "^1.5.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.1.0",
    "karma-remap-istanbul": "^0.2.2",
    "protractor": "^4.0.14",
    "tachyons": "^4.6.2",
    "ts-node": "^1.7.3",
    "tslint": "^4.5.1",
    "typescript": "^2.2.1"
  }
}

I can also produce this error only when using yarn instead of npm install

I had similar issue with yarn. My problem was resolved by deleting the yarn.lock file and re-running the yarn command.

@cport1 same for me.

I also had to revert back to rc2 from rc4 in order to have my ng serve work again. As previously mentioned, works with npm install but not with yarn

Ok, I reinstalled yarn using my package manager, removed the node_moduls. used yarn to install. Problem stays the same. removed node_modules yet again, and used npm to install, the problem goes away. Even if you use yarn after that.

conclusion. This problem happens and is reproducible if you use yarn to install your packages. (which is a shame, as yarn is at least 2 times faster in my situation.)

reason (an educated guess!): As yarn is more strict on installing, it probably forces a slightly older dependency in the tree somewhere.

I ran into the same issue, this fixed it for me, see reference here: https://github.com/angular/angular-cli/issues/6425

Here are the versions I used to get it running:

yarn: 1.1.0, angular-cli: 1.4.7, typescript: 2.2.2

@isNull – yes absolutely! That’s one thing we had to do as well. We explicitly reference the index file as well. Sorry; I had forgotten that we had also done that.

In my case, the problem was that @angular/cli and it’s related tools didn’t believe in using export default to export anything so trying to import submodules with import name from './module' syntax just imported undefined instead. Avoiding default exports solved this issue for me.

Same thing here. I upgraded easily from beta.28 to rc.0, then rc.1 and rc.2. However, I face the same problem when upgrading to rc.4. I had to revert to rc.2 for my app to build again.

Here is my package.json:

    "name": "my-app",
    "version": "0.0.1",
    "license": "UNLICENSED",
    "angular-cli": {},
    "scripts": {
        "ng": "ng",
        "hmr": "ng serve --hmr -e=hmr",
        "start": "ng serve",
        "build": "ng build",
        "test": "ng test",
        "lint": "ng lint",
        "pree2e": "webdriver-manager update --standalone false --gecko false",
        "e2e": "protractor"
    },
    "private": true,
    "dependencies": {
        "@angular/common": "^2.4.0",
        "@angular/compiler": "^2.4.0",
        "@angular/core": "^2.4.0",
        "@angular/forms": "^2.4.0",
        "@angular/http": "^2.4.0",
        "@angular/material": "2.0.0-beta.2",
        "@angular/platform-browser": "^2.4.0",
        "@angular/platform-browser-dynamic": "^2.4.0",
        "@angular/router": "^3.4.7",
        "@angularclass/hmr": "^1.2.2",
        "@covalent/core": "^1.0.0-beta.2-1",
        "@ngrx/core": "^1.2.0",
        "@ngrx/effects": "^2.0.1",
        "@ngrx/store": "^2.2.1",
        "@ngrx/store-devtools": "^3.2.3",
        "@ngx-translate/core": "^6.0.0",
        "@ngx-translate/http-loader": "^0.0.3",
        "angular2-jwt": "^0.1.28",
        "angular2-moment": "^1.3.3",
        "core-js": "^2.4.1",
        "hammerjs": "^2.0.8",
        "karma-phantomjs-launcher": "^1.0.2",
        "lodash": "^4.17.4",
        "merge-options": "0.0.64",
        "phantomjs-prebuilt": "^2.1.14",
        "rxjs": "^5.1.0",
        "ts-helpers": "^1.1.1",
        "zone.js": "^0.7.6"
    },
    "devDependencies": {
        "@angular/cli": "1.0.0-rc.2",
        "@angular/compiler-cli": "^2.4.0",
        "@types/jasmine": "^2.5.46",
        "@types/lodash": "^4.14.57",
        "@types/node": "^7.0.10",
        "codelyzer": "~2.0.0",
        "jasmine-core": "2.5.2",
        "karma": "1.4.1",
        "karma-chrome-launcher": "^2.0.0",
        "karma-cli": "^1.0.1",
        "karma-coverage-istanbul-reporter": "^0.2.0",
        "karma-jasmine": "^1.1.0",
        "karma-jasmine-html-reporter": "^0.2.2",
        "protractor": "~5.1.0",
        "ts-node": "2.0.0",
        "tslint": "^4.4.2",
        "typescript": "~2.2.1"
    }
}

@hansl I can confirm the problem is now gone. Even with a yarn installed project!

Just did an update today, to latest cli and Angular 4. this is still happening: image

Only on the first compile, afterwards it works.

NOTE, this only happens if you installed the project with YARN, not with NPM install