Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ng build Aot not working #3141

Closed
harilalinapp opened this issue Nov 15, 2016 · 13 comments
Closed

ng build Aot not working #3141

harilalinapp opened this issue Nov 15, 2016 · 13 comments
Labels
needs: investigation Requires some digging to determine if action is needed

Comments

@harilalinapp
Copy link

harilalinapp commented Nov 15, 2016

When i run ng build -prod --aot i got this error.

AuthModule is not an NgModule

My module is

import { NgModule } from "@angular/core"

import { AuthRoutes } from "./auth.routes"
import { LoginComponent } from './login.component';
import { ReactiveFormsModule } from '@angular/forms';
import { CoreModule } from '../core.module';
import { MaterialModule } from '@angular/material';
import { SharedModule } from '../shared/shared.module';

@NgModule({
	declarations: [
		LoginComponent
	],
	imports: [AuthRoutes, MaterialModule, SharedModule, CoreModule, ReactiveFormsModule],
	providers: []
})
export class AuthModule { }

I couldn't figure out whats wrong with my module. I have been loading this as lazy loading

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LoginComponent } from './auth/login.component';
import { AuthGuard } from './auth/auth.guard';

const routes: Routes = [
	{
		path:'',
		redirectTo: '/login',
		pathMatch: 'full'
	},
	{
		path:'login',
		//component: LoginComponent
		loadChildren: 'app/auth/auth.module#AuthModule',
	}
];
export const RoutingModule = RouterModule.forRoot(routes, { useHash: true });

Angular cli : "1.0.0-beta.19-3",

@sclausen
Copy link

+1

@elvirdolic
Copy link

you have to put your routes in a module and import it

see thread: #2515 (comment)

`import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';

import { HomeComponent } from './home';

export const appRoutes: Routes = [
{path: '', component: HomeComponent},
{path: 'info', loadChildren: './info/info.module#InfoModule' },
];

@NgModule({
imports: [
RouterModule.forRoot(appRoutes)
],
exports: [
RouterModule
],
providers: []
})
export class AppRoutingModule {}
`

@harilalinapp
Copy link
Author

Hi,
It's solved my issue and i can run the 'ng serve --aot' now .
But other error showed up on browser.

error_handler.js:47 EXCEPTION: Uncaught (in promise): Error: Cannot find module 'app/auth/auth.module.ngfactory'.
Error: Cannot find module 'app/auth/auth.module.ngfactory'.
    at webpackEmptyContext (http://localhost:4200/main.bundle.js:61294:8)
    at SystemJsNgModuleLoader.loadFactory (http://localhost:4200/main.bundle.js:47921:40)
    at SystemJsNgModuleLoader.load (http://localhost:4200/main.bundle.js:47902:35)
    at RouterConfigLoader.loadModuleFactory (http://localhost:4200/main.bundle.js:10598:128)
    at RouterConfigLoader.load (http://localhost:4200/main.bundle.js:10590:81)
    at MergeMapSubscriber.project (http://localhost:4200/main.bundle.js:68460:111)
    at MergeMapSubscriber._tryNext (http://localhost:4200/main.bundle.js:12799:27)
    at MergeMapSubscriber._next (http://localhost:4200/main.bundle.js:12789:18)
    at MergeMapSubscriber.Subscriber.next (http://localhost:4200/main.bundle.js:2131:18)
    at ScalarObservable._subscribe (http://localhost:4200/main.bundle.js:59985:24)

I think it's not finding the lazy loaded module in AoT mode.

@achimha
Copy link

achimha commented Nov 16, 2016

I get AppModule is not an NgModule with --aot but not without. The error information is extremely sparse, it's not the routing like described above.

How does one go about debugging this "is not an NgModule" error for the actual cause?

@harilalinapp
Copy link
Author

harilalinapp commented Nov 16, 2016

After upgrading to : 1.0.0-beta.20-4 running 'ng serve --aot` shows another error
#0% compilingcompiler.AnimationParser is not a constructor
TypeError: compiler.AnimationParser is not a constructor
at Function.CodeGenerator.create (/Users/iminar/Dev/angular/modules/@angular/compiler-cli/src/codegen.ts:141:9)
at AotPlugin._make (/home/harilal/works/project/node_modules/@ngtools/webpack/src/plugin.js:189:54)
at Compiler. (/home/harilal/works/project/node_modules/@ngtools/webpack/src/plugin.js:157:75)
at Compiler.applyPluginsParallel (/home/harilal/works/project/node_modules/tapable/lib/Tapable.js:156:14)
at Compiler. (/home/harilal/works/project/node_modules/webpack/lib/Compiler.js:463:8)
at Compiler.applyPluginsAsync (/home/harilal/works/project/node_modules/tapable/lib/Tapable.js:73:70)
at Compiler.compile (/home/harilal/works/project/node_modules/webpack/lib/Compiler.js:456:7)
at Watching. (/home/harilal/works/project/node_modules/webpack/lib/Compiler.js:46:17)
at next (/home/harilal/works/project/node_modules/tapable/lib/Tapable.js:81:11)
at Compiler.invalidAsyncPlugin (/home/harilal/works/project/node_modules/webpack-dev-middleware/middleware.js:119:3)
at next (/home/harilal/works/project/node_modules/tapable/lib/Tapable.js:83:14)
at Compiler. (/home/harilal/works/project/node_modules/webpack/lib/CachePlugin.js:31:4)
at Compiler.applyPluginsAsync (/home/harilal/works/project/node_modules/tapable/lib/Tapable.js:85:13)
at Watching._go (/home/harilal/works/project/node_modules/webpack/lib/Compiler.js:44:16)
at Watching. (/home/harilal/works//project/node_modules/webpack/lib/Compiler.js:36:8)
at Compiler.readRecords (/home/harilal/works/project/node_modules/webpack/lib/Compiler.js:367:10)
at new Watching (/home/harilal/works/project/node_modules/webpack/lib/Compiler.js:33:16)
at Compiler.watch (/home/harilal/works/project/node_modules/webpack/lib/Compiler.js:204:17)
at module.exports (/home/harilal/works/project/node_modules/webpack-dev-middleware/middleware.js:146:27)
at new Server (/home/harilal/works/project/node_modules/webpack-dev-server/lib/Server.js:43:20)
at Class.run (/home/harilal/works/project/node_modules/angular-cli/tasks/serve-webpack.js:74:22)
at /home/harilal/works/project/node_modules/angular-cli/commands/serve.js:92:26
at process._tickCallback (internal/process/next_tick.js:103:7)

@filipesilva filipesilva added feature: aot needs: investigation Requires some digging to determine if action is needed labels Nov 22, 2016
@greengerong
Copy link

How about this issue?

I also meet same problem with lazy load module BlogAppModule :

$ ng build --aot
10% building modules 4/5 modules 1 active ...ar2/rebirth/src/styles/bootstrap.scssBlogAppModule is not an NgModule
Error: BlogAppModule is not an NgModule
    at AotPlugin.getNgModuleMetadata (/Users/zxgerong/project/opensource/js/angular2/rebirth/node_modules/@ngtools/webpack/src/plugin.js:297:19)
    at AotPlugin._processNgModule (/Users/zxgerong/project/opensource/js/angular2/rebirth/node_modules/@ngtools/webpack/src/plugin.js:241:42)
    at _loop_1 (/Users/zxgerong/project/opensource/js/angular2/rebirth/node_modules/@ngtools/webpack/src/plugin.js:271:35)
    at AotPlugin._processNgModule (/Users/zxgerong/project/opensource/js/angular2/rebirth/node_modules/@ngtools/webpack/src/plugin.js:290:13)
    at /Users/zxgerong/project/opensource/js/angular2/rebirth/node_modules/@ngtools/webpack/src/plugin.js:217:39
    at tryCatch (/Users/zxgerong/project/opensource/js/angular2/rebirth/node_modules/es6-promise/dist/lib/es6-promise/-internal.js:195:12)
    at invokeCallback (/Users/zxgerong/project/opensource/js/angular2/rebirth/node_modules/es6-promise/dist/lib/es6-promise/-internal.js:210:13)
    at publish (/Users/zxgerong/project/opensource/js/angular2/rebirth/node_modules/es6-promise/dist/lib/es6-promise/-internal.js:178:7)
    at flush (/Users/zxgerong/project/opensource/js/angular2/rebirth/node_modules/es6-promise/dist/lib/es6-promise/asap.js:94:5)
    at nextTickCallbackWith0Args (node.js:452:9)
    at process._tickCallback (node.js:381:13)

@unsafecode
Copy link

I also get this curious error, but only with a very specific setup: using angular2-router-loader and not putting the route config within the AppModule (then, change the router config at runtime), everything works (even if some routes don't load properly then).

On the other hand, if I put my lazy route in AppModule, I get the error.

@kentoj
Copy link

kentoj commented Dec 6, 2016

I am getting this problem even though I am not using AOT. This happens in the latest beta.22-1.
It happens for me for the Semantic UI module:

ng build --prod
 10% building modules 2/2 modules 0 activeSuiModule is not an NgModule
Error: SuiModule is not an NgModule
    at AotPlugin.getNgModuleMetadata (/Users/kent/git/dccs/abacus/node_modules/@ngtools/webpack/src/plugin.js:332:19)
    at /Users/kent/git/dccs/abacus/node_modules/@ngtools/webpack/src/plugin.js:345:51
    at Array.map (native)
    at AotPlugin.extractLoadChildren (/Users/kent/git/dccs/abacus/node_modules/@ngtools/webpack/src/plugin.js:343:14)
    at AotPlugin._processNgModule (/Users/kent/git/dccs/abacus/node_modules/@ngtools/webpack/src/plugin.js:272:38)
    at /Users/kent/git/dccs/abacus/node_modules/@ngtools/webpack/src/plugin.js:242:39
    at process._tickCallback (internal/process/next_tick.js:103:7)

@antonybudianto
Copy link
Contributor

antonybudianto commented Dec 6, 2016

same here, not happening on @ngtools/webpack 1.1.6

@ngtools/webpack 1.1.9
@angular/ 2.2.3/3.2.3

0% compilingError: AppModule is not an NgModule
    at AotPlugin.getNgModuleMetadata (/Users/antony/Documents/Code/Web/angular-webpack-starter/node_modules/@ngtools/webpack/src/plugin.js:332:19)
    at AotPlugin._processNgModule (/Users/antony/Documents/Code/Web/angular-webpack-starter/node_modules/@ngtools/webpack/src/plugin.js:271:42)
    at /Users/antony/Documents/Code/Web/angular-webpack-starter/node_modules/@ngtools/webpack/src/plugin.js:242:39

reproduction repo, just update the package.json for ngtools and angular packages

@kentoj
Copy link

kentoj commented Dec 6, 2016

What fixed it for me temporarily was to downgrade to angular-cli@1.0.0-beta.21. I had to do that globally and in the local devDependencies for my project. Oddly enough the angular-cli version in angular-cli.json did not matter.

@bhshawon
Copy link

bhshawon commented Feb 1, 2017

Same issue

@filipesilva
Copy link
Contributor

Closing as obsolete.

@angular-automatic-lock-bot
Copy link

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.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
needs: investigation Requires some digging to determine if action is needed
Projects
None yet
Development

No branches or pull requests

10 participants