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/[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!
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
Downgrading typescript to 2.0.2 and keeping 1.0.0-rc.2 is what worked for me.
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.
I tested upgrading to @angular/cli 1.0.0and it seamed to work, except I'm using angular material and Covalent, both of them not yet compatible with Angular 4.
{ "name": "admin2", "version": "0.0.0", "license": "MIT", "angular-cli": {}, "scripts": { "ng": "ng", "start": "ng serve", "test": "ng test", "pree2e": "webdriver-manager update --standalone false --gecko false", "e2e": "protractor" }, "private": true, "dependencies": { "@angular/animations": "~4.0.0", "@angular/common": "~2.3.1", "@angular/compiler": "~2.4.1", "@angular/core": "~2.3.1", "@angular/forms": "~2.3.1", "@angular/http": "~2.3.1", "@angular/platform-browser": "~2.3.1", "@angular/platform-browser-dynamic": "~2.3.1", "@angular/router": "~3.3.1", "angular-eonasdan-datetimepicker": "~0.3.9", "angular-in-memory-web-api": "~0.3.1", "bootstrap": "~3.3.7", "bootstrap-datepicker": "~1.6.4", "chart.js": "~2.5.0", "core-js": "~2.4.1", "datatables.net": "~1.10.13", "datatables.net-dt": "~1.10.13", "echarts": "~3.4.0", "eonasdan-bootstrap-datetimepicker": "~4.17.47", "jquery": "~3.1.1", "jquery-ui-dist": "~1.12.1", "moment": "~2.18.1", "ng2-bootstrap": "~1.6.3", "ng2-charts": "~1.5.0", "ng2-toastr": "~1.6.0", "ng2-translate": "5.0.0", "portfinder": "1.0.9", "rxjs": "~5.0.0", "tether": "~1.4.0", "tinymce": "4.5.3", "ts-helpers": "~1.1.1", "zone.js": "~0.7.2", "ztree": "3.5.24" }, "devDependencies": { "@angular/cli": "^1.0.3", "@angular/compiler-cli": "2.4.1", "@types/jasmine": "2.5.38", "@types/node": "^6.0.42", "codelyzer": "~2.0.0-beta.1", "jasmine-core": "2.5.2", "jasmine-spec-reporter": "2.5.0", "karma": "1.2.0", "karma-chrome-launcher": "^2.0.0", "karma-cli": "^1.0.1", "karma-jasmine": "^1.0.2", "karma-remap-istanbul": "^0.2.1", "protractor": "~4.0.13", "ts-node": "1.2.1", "tslint": "^4.3.0", "typescript": "2.0.10" } } I have the same question,what can I do?
@lilingling3 Make sure you update all your dependencies to the same version. I see:
"@angular/animations": "~4.0.0", "@angular/common": "~2.3.1", "@angular/compiler": "~2.4.1",
3 different angular versions! If you are updating your project, make sure you have the same version on all @angular stuff for use. I would recommend the last stable version (currently 4.1.2).
Fix the package.json. delete node_modules and run npm install again. (or the yarn version of that)
Before I used angular-cli ,I use angular/cli now.
I can also produce this error only when using yarn instead of npm install
@cport1 same for me.
I have this problem after a npm update with typescript 2.3.2. I don't know if it's related but the first time I forgot to stop the project before I executed the command and it give me an error about not being able to delete some files. I had to delete the entire node_module folder and execute a npm install to fix it.
I also get this error.Watch tips below.
I change pachage.json typescript to 2.2.2,then delete node_modules, re npm install,and ng serve.Wo pass.
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).
@sjswoboda Did you find anything to resolve the issue? This is haunting us for the past week and wasting away our time. Using Typescript 2.1.5 is not an option as Angular Material is not working with it, and newer versions all end up with xy is not an NgModule
@IsNull -- we've been through so many errors in the past few weeks, so I cannot remember what fixes what. Based on our change logs, the issue appears to be:
- Ensuring that all angular projects are on the same version. No more ^4.2.6 or ~4.2.6. We just put in the exact version:
"@angular/animations": "4.2.6",
"@angular/common": "4.2.6",
"@angular/compiler": "4.2.6",
"@angular/compiler-cli": "4.2.6",
"@angular/core": "4.2.6",
"@angular/forms": "4.2.6",
"@angular/http": "4.2.6",
We have since upgraded to 4.3.4 and that is working fine for us. We are using TypeScript 2.4.1 and angular/cli is 1.2.1. So far, we haven't seen these errors again (don't worry, once you resolve these, you'll just get different problems).
I am sorry I can't be of more help.
@sjswoboda Thank you for your support. We have startet tackling the issue (or issues) down and make it reproducible #7384. What I know for sure is that subsets of the now problematic libraries have worked in the same environment. Which is a clear indication that a very nasty error is at the core of all this - some constellation of configuration, dependencies or actual code in use will trigger it.
(don't worry, once you resolve these, you'll just get different problems)
There are so many layers, configurations and involved tools, and the error messages are not really helping. Im still amazed how complicated this all turned out. 😅
@sjswoboda The cause in our case was that we used to export the index.ts files by omiting their name:
export * from 'components/myfeature' (to export components/myfeature/index.ts)
However, this is not supported by ng/ngc and as a workaround we had to explicitly name the index:
export * from 'components/myfeature/index'
However, all the tooling and standards explicitly allow to omit the index name...
See #7394 for the bug report.
@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.
I had this issue when I upgraded yarn to 1.2.1. If I rollback to 1.0.0, it works. Maybe there is a newer version between 1.0.0 and 1.2.1 that works. I will keep 1.0.0 for the moment
just ran into this issue upgrading from angular-cli 1.3 to 1.5.5. Removed node_modules , reinstalled with NPM - same. Removed node_modules, reinstalled with yarn - same. Removed node_modules, removed all yarn-related files, reinstalled with npm, and it worked. VERY strange
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