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
- Upgrade TS to fix ng build issue See https://github.com/angular/angular-cli/issues/4594 — committed to paullessing/natasha-smart-home by paullessing 7 years ago
- package.json: upgraded angular to 2.4.1, to solve "ERROR in AppModule is not an NgModule" http://stackoverflow.com/questions/41431682/appmodule-is-not-an-ngmodule-error-despite-setting-typescript-to-... — committed to karol-depka/flexagenda by karol-depka 7 years ago
- bumped into https://github.com/angular/angular-cli/issues/4594 — committed to gpolyn/angular-nvd3 by gpolyn 7 years ago
I got the same problem. On ubuntu 16. But only on the first build: 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
fixes the problem, but the problem remains if you do
yarn
instead ofnpm 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:
@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 usingyarn
.Also I have deleted
node_modules
folder and myyarn.lock
file.Here is my package.json file.
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 usingexport default
to export anything so trying to import submodules withimport name from './module'
syntax just importedundefined
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:
@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:
Only on the first compile, afterwards it works.
NOTE, this only happens if you installed the project with YARN, not with NPM install