angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ERROR in AppModule is not an NgModule

Open tHesTx opened this issue 9 years ago • 43 comments

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/[email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] +-- [email protected] `-- [email protected]

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 [email protected]: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue

But as you can see above I have "[email protected]" - 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!

tHesTx avatar Feb 10 '17 11:02 tHesTx

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

SanderElias avatar Feb 10 '17 13:02 SanderElias

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

dessalines avatar Feb 10 '17 16:02 dessalines

Thanks @dessalines Not sure whats issue with yarn but your instructions worked.

pinalbhatt avatar Feb 10 '17 17:02 pinalbhatt

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.

SanderElias avatar Feb 11 '17 03:02 SanderElias

This problem seems to occur with Typescript 2.1.6.

If you clean your node modules, change Typescript to [email protected] and do a yarn install or npm install, the problem should be resolved.

djedje72 avatar Feb 14 '17 13:02 djedje72

So, for me, should I install this yarn? I do not use it

tHesTx avatar Feb 14 '17 14:02 tHesTx

@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.

SanderElias avatar Feb 14 '17 14:02 SanderElias

@SanderElias Yes it was just on the first run for ng serve but can you do ng build? @tHesTx i think you can do npm install if you don't use yarn

djedje72 avatar Feb 14 '17 15:02 djedje72

I don't know what to do anymore, nothing works. DO I have to update something in package.json or angular-cli.json in my project ? Building gives the same error

tHesTx avatar Feb 14 '17 15:02 tHesTx

@tHesTx For me, i'd to change "typescript": "2.1.6" to "typescript":"2.1.5" in my package.json file because i use local typescript version.

If you use global version, you can try: npm uninstall -g typescript then npm install -g [email protected]

djedje72 avatar Feb 14 '17 15:02 djedje72

@djedje72 I've done that, currently is set to "typescript": "2.1.5". Before to do the first angular-cli update which got me to this point it was like this: "typescript": "~2.0.3". Uninstall and reinstall too. I've also updated the "@angular/cli": "1.0.0-beta.24", "angular-cli": "1.0.0-beta.24", from "devDependencies" to 31, in angular-cli.json: "version": "1.0.0-beta.24", -> to 31 as well. PS: If I do these changes before npm install, when I run npm install gives me some errors about the CLI version, somthing like the requested(beta.31) version not exists

tHesTx avatar Feb 14 '17 15:02 tHesTx

Ok, I've generated a new app with angular-cli which works, but in package.json it uses this: "typescript": "~2.0.0" - but I have installed 2.1.5 globally. Why is that?

tHesTx avatar Feb 14 '17 15:02 tHesTx

Your local Typescript version doesn't necessarily have to match your global. CLI generates a package.json with default dependencies it requires, but you can (and should) updated them according to your needs.

I actually had an issue trying to run angular-2.4.7 with typescript 2.0.0 but after updating my project's package.json with typescript 2.1.6 the issue was resolved. I assume if you do the same it will resolve your issue as well.

#goodnessSquad

aviramga avatar Feb 15 '17 19:02 aviramga

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

SanderElias avatar Feb 23 '17 14:02 SanderElias

This is a disconnect between Angular 4 and 2.4 that happens in some cases. You probably have an @angular/core version in the CLI node_modules that is different than your application's node_modules.

Try with the RC.0, we did fix a few of those mismatch. Also, try to clear your node_modules and reinstall.

hansl avatar Feb 25 '17 19:02 hansl

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

SanderElias avatar Feb 27 '17 07:02 SanderElias

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

frenkan avatar Mar 11 '17 09:03 frenkan

FYI, a fix for me was to downgrade to typescript "2.0.2" while keeping cli version at "1.0.0-rc.2".

Marcidius avatar Mar 21 '17 15:03 Marcidius

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"
  }
}

rajinder-yadav avatar Mar 22 '17 00:03 rajinder-yadav

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"
    }
}

Arnaud73 avatar Mar 23 '17 19:03 Arnaud73