You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
@ngtools/webpack complainning about not an NgModule #3157
Error: AppModule is not an NgModule
at AotPlugin.getNgModuleMetadata (/var/build/node_modules/@ngtools/webpack/src/plugin.js:297:19)
at AotPlugin._processNgModule (/var/build/node_modules/@ngtools/webpack/src/plugin.js:241:42)
at /var/build/node_modules/@ngtools/webpack/src/plugin.js:217:39
at process._tickCallback (internal/process/next_tick.js:103:7)
at Module.runMain (module.js:606:11)
at run (bootstrap_node.js:394:7)
Done in 7.29s.
Reacted by Antony Budianto, Jim Griswold, Mark Holmes, Dominik Hardtke, Evgeniy OZ, Mashhood Rastgar, Suguru Inatomi, Jonathan Bonnefoy, Dwight Gunning, Mirko Nasato and 19 more
Without it (i.e. just using @ngtools/webpack), that error message would appear if entryModule points to the wrong path (i.e. ' ./src/app/app.module#AppModule' must be a valid path)
Note I used absolute paths, because I saw some commits in this repo saying something about relative paths not working. I am pretty sure my path was valid.
AotPlugin.prototype.getNgModuleMetadata=function(staticSymbol){varngModules=this._reflector.annotations(staticSymbol).filter(function(s){returnsinstanceofcore_1.NgModule;});if(ngModules.length===0){thrownewError(staticSymbol.name+" is not an NgModule");}returnngModules[0];};
When enabling AoT, it didn't pass because I had some imports with .ts in the end. I just removed in all lines it found and it didn't complain anymore. Maybe it's the same case.
BTW, I still don't have my app successfully in AoT. I'm also learning in this topic at this very moment.
@marinho Thanks for your response. Yes, its all without a suffix. Somehow it works now, I deleted my node_modules folder and installed all dependencies again. It's weird as I updated them before as well.
Im also getting the same. If I build a new project using ng new and run -aot on that, it works fine - but on my own project im getting Error: AppModule is not an NgModule. I have removed everything from my AppModule and AppComponent.
@princemaple What do you mean?
Yesterday I founded an example here https://github.com/blacksonic/angular2-aot-webpack (big thanks to the author). But my roadmap is a little bit different
And now, I'm using webpack. Here is a part of my webpack.config.
.....
{
test: /.ts$/,
loaders: env.aot ?
['awesome-typescript-loader?tsconfig=./client-code/src/tsconfig.json', 'angular2-template-loader', 'angular2-router-loader?genDir=./client-code/src/aot-compiled/app&aot=true'] :
['awesome-typescript-loader?tsconfig=./client-code/src/tsconfig.json', 'angular2-template-loader', 'angular2-router-loader']
}
...
With 'angular2-router-loader' I can split my bundles.
Here are my "scripts" from packages.json
"scripts": {
"prepublish": "yarn run build",
"build": "yarn run clean && yarn webpack",
"build:jit": "yarn run clean && yarn webpack -- --env.production",
"build:production": "yarn run clean && yarn run compiler:aot && yarn webpack -- --env.aot --env.production",
"compiler:aot": "ngc -p client-code/src/tsconfig-aot.json",
"clean": "rimraf client-code/dist/* client-code/src/aot-compiled"
},
I experienced the problem with "AppModule is not an NgModule" after trying to run "./node_modules/.bin/ngc" to build a translated version (the build failed and the app wasn't translated).
I tried to reinstall, change versions etc. but nothing worked.
I finally realized that something had created an extra node_modules folder under the src folder. It only contains "@angular" and "rxjs" folders. When I delete this extra node_modules I can build again.
However I still can't figure out how to use i18n - but that is another problem.
In case anyone stumbles across this, in my case it was misconfiguration. I was getting a null is not an NgModule error, which was because my entryModule missed of the name of the module:
new ngtools.AotPlugin({
tsConfigPath: './tsconfig.json',
entryModule: root('src/app/pager')
})
became
new ngtools.AotPlugin({
tsConfigPath: './tsconfig.json',
entryModule: root('src/app/pager') + '#PagerComponentModule'
})
Activity
marinho commentedon Nov 17, 2016
@princemaple can you paste your AotPlugin configuration, please?
marinho commentedon Nov 17, 2016
oops, I missed this is an angular-cli related.
Without it (i.e. just using
@ngtools/webpack), that error message would appear ifentryModulepoints to the wrong path (i.e.' ./src/app/app.module#AppModule'must be a valid path)princemaple commentedon Nov 17, 2016
I had a very simple minimal AotPlugin config, something like
princemaple commentedon Nov 17, 2016
Note I used absolute paths, because I saw some commits in this repo saying something about relative paths not working. I am pretty sure my path was valid.
marinho commentedon Nov 17, 2016
I see. In that case, I have no more to add.
janwo commentedon Nov 17, 2016
I have the same problem here. I also configured it like @princemaple. BTW: I have not defined any entry point.
princemaple commentedon Nov 17, 2016
@marinho thanks for taking a look still!
janwo commentedon Nov 17, 2016
Whereas
staticSymbolis......and
this._reflector.annotations(staticSymbol)is[].Seems like the annotations are not set correctly? The path is valid.
marinho commentedon Nov 18, 2016
@janwo did you try without ".ts" in
filePath?When enabling AoT, it didn't pass because I had some imports with
.tsin the end. I just removed in all lines it found and it didn't complain anymore. Maybe it's the same case.BTW, I still don't have my app successfully in AoT. I'm also learning in this topic at this very moment.
janwo commentedon Nov 18, 2016
@marinho Thanks for your response. Yes, its all without a suffix. Somehow it works now, I deleted my node_modules folder and installed all dependencies again. It's weird as I updated them before as well.
dhardtke commentedon Nov 18, 2016
I have the same problem, see #2667
mashhoodr commentedon Nov 22, 2016
Im also getting the same. If I build a new project using
ng newand run -aot on that, it works fine - but on my own project im gettingError: AppModule is not an NgModule. I have removed everything from my AppModule and AppComponent.dhardtke commentedon Nov 22, 2016
I have the problem with the AotPlugin for Webpack...
jessezhang91 commentedon Nov 22, 2016
It seems like
[email protected]is causing the issue. Downgrading to2.0.10seems to make it pick up the metadata correctly.zakdances commentedon Dec 2, 2016
Strangely, this error shows up on
2.2.4but not2.2.3.43 remaining items
arciisine commentedon Jan 9, 2017
Angular 2.4.2 just landed which fixed TS 2.1 support. I've successfully built 2.4.2 with typescript 2.1.4 and beta 24 of the cli.
sbley commentedon Jan 9, 2017
@arciisine Which Angular dependency has to be updated to 2.4.2? common, core?
jkuri commentedon Jan 9, 2017
@sbley
compiler-cliat least, preferable all.sbley commentedon Jan 9, 2017
Yeah, in the end these are peer dependencies. If you update one you gotta update all...
ichent commentedon Jan 9, 2017
@princemaple What do you mean?
Yesterday I founded an example here https://github.com/blacksonic/angular2-aot-webpack (big thanks to the author). But my roadmap is a little bit different
And now, I'm using webpack. Here is a part of my webpack.config.
.....
{
test: /.ts$/,
loaders: env.aot ?
['awesome-typescript-loader?tsconfig=./client-code/src/tsconfig.json', 'angular2-template-loader', 'angular2-router-loader?genDir=./client-code/src/aot-compiled/app&aot=true'] :
['awesome-typescript-loader?tsconfig=./client-code/src/tsconfig.json', 'angular2-template-loader', 'angular2-router-loader']
}
...
With 'angular2-router-loader' I can split my bundles.
Here are my "scripts" from packages.json
"scripts": {
"prepublish": "yarn run build",
"build": "yarn run clean && yarn webpack",
"build:jit": "yarn run clean && yarn webpack -- --env.production",
"build:production": "yarn run clean && yarn run compiler:aot && yarn webpack -- --env.aot --env.production",
"compiler:aot": "ngc -p client-code/src/tsconfig-aot.json",
"clean": "rimraf client-code/dist/* client-code/src/aot-compiled"
},
rgiosa commentedon Jan 9, 2017
Yeap, this is now working with Typescript 2.1.4!
princemaple commentedon Jan 10, 2017
@ichent thanks for the information about the alternative!
ichent commentedon Jan 10, 2017
@princemaple You are welcome!
larssin commentedon Jan 14, 2017
Look for unwanted node_modules folders...
I experienced the problem with "AppModule is not an NgModule" after trying to run "./node_modules/.bin/ngc" to build a translated version (the build failed and the app wasn't translated).
I tried to reinstall, change versions etc. but nothing worked.
I finally realized that something had created an extra node_modules folder under the src folder. It only contains "@angular" and "rxjs" folders. When I delete this extra node_modules I can build again.
However I still can't figure out how to use i18n - but that is another problem.
AckerApple commentedon May 17, 2017
I had one time forgot to add "typings"="index.d.ts" key to my package.json file. Once I did, I stopped getting Please add @NgModule error
Maloric commentedon May 22, 2017
In case anyone stumbles across this, in my case it was misconfiguration. I was getting a
null is not an NgModuleerror, which was because my entryModule missed of the name of the module:became
pratiksha-chandel commentedon Jun 13, 2017
ng build and ng serve is not working for me .gives error
ERROR in /home/pratiksha/migration//app/shared/user.service.spec.ts (7,3): Cannot find name 'beforeEach'.
ERROR in /home/pratiksha/migration/app/shared/user.service.spec.ts (13,3): Cannot find name 'it'.
ERROR in /home/pratiksha/migration/app/shared/user.service.spec.ts (14,5): Cannot find name 'expect'.
ERROR in PopoverModule is not an NgModule
ERROR in multi ./src/styles.css ./src/css/main.css ./src/css/font-awesome.min.css ./src/css/daterangepicker.css ./src/css/style.css ./src/css/style-bootstrap.css ./src/css/style-default.css ./src/css/style-material.css
Module not found: Error: Can't resolve '/home/pratiksha/migration/src/css/main.css' in '/home/pratiksha/migration/node_modules/@angular/cli/models/webpack-configs'
@ multi ./src/styles.css ./src/css/main.css ./src/css/font-awesome.min.css ./src/css/daterangepicker.css ./src/css/style.css ./src/css/style-bootstrap.css ./src/css/style-default.css ./src/css/style-material.css
try all but not working for me .
angular cli is not working after upgrade -this is not supporting to .spec.ts file .
why this is happing ?
angular-automatic-lock-bot commentedon Sep 7, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.