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 fails #4043

Closed
rolandjitsu opened this issue Jan 16, 2017 · 8 comments
Closed

ng build --aot fails #4043

rolandjitsu opened this issue Jan 16, 2017 · 8 comments
Labels

Comments

@rolandjitsu
Copy link

Please provide us with the following information:

OS?

Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)

OS X El Capitan

Versions.

Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here:

angular-cli: 1.0.0-beta.25.5
node: 6.7.0
os: darwin x64
@angular/common: 2.4.3
@angular/compiler: 2.4.3
@angular/core: 2.4.3
@angular/forms: 2.4.3
@angular/http: 2.4.3
@angular/platform-browser: 2.4.3
@angular/platform-browser-dynamic: 2.4.3
@angular/router: 3.4.3
@angular/material: 2.0.0-beta.1

Repro steps.

Was this an app that wasn't created using the CLI? What change did you do on your code? etc.

If I run ng build --aot it throws an error after it logs the bundles that were created.

The log given by the failure.

Normally this include a stack trace and some more information.

Hash: f623b656056e9a59a302                                                               
Time: 14288ms
chunk    {0} scripts.b070e2134bb20fc4e5f5.bundle.js (scripts) 730 kB {4} [initial] [rendered]
chunk    {1} styles.fe1bc11c112063cca818.bundle.css (styles) 21.9 kB {4} [initial] [rendered]
chunk    {2} main.3269aa95e662115bc916.bundle.js (main) 1.97 kB {3} [initial] [rendered]
chunk    {3} vendor.9340472a0450b55ed1fe.bundle.js (vendor) 1.08 MB [initial] [rendered]
chunk    {4} inline.a6aa1cbd561bcc42ae6c.bundle.js (inline) 0 bytes [entry] [rendered]

ERROR in providers.forEach is not a function

ERROR in ./src/main.ts
Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory' in '/Users/rolandjitsu/Projects/infarm/dashboard/src'
 @ ./src/main.ts 4:0-74
 @ multi main

ERROR in ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js
Module not found: Error: Can't resolve '/Users/rolandjitsu/Projects/infarm/dashboard/src/$$_gendir' in '/Users/rolandjitsu/Projects/infarm/dashboard/node_modules/@angular/core/src/linker'
 @ ./~/@angular/core/src/linker/system_js_ng_module_factory_loader.js 69:15-36 85:15-102
 @ ./~/@angular/core/src/linker.js
 @ ./~/@angular/core/src/core.js
 @ ./~/@angular/core/index.js
 @ ./src/main.ts
 @ multi main

Mention any other details that might be useful.


Thanks! We'll be in touch soon.

@filipesilva
Copy link
Contributor

It looks like the real error is ERROR in providers.forEach is not a function when then breaks the AoT'd app.module. Can you show me the code of ./src/app/app.module.ts?

@rolandjitsu
Copy link
Author

Yes I can:

import {NgModule} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';

/**
 * Feature Modules
 */
import {CoreModule, PreloadSelectedModulesOnly} from './core';
import {SharedModule} from './shared/shared.module';

/**
 * Components
 */
import {AppComponent} from './app.component';
import {LayoutComponent} from './layout/layout.component';
import {HomeComponent} from './home/home.component';
import {NotificationsComponent} from './notifications/notifications.component';
import {RecipesComponent} from './recipes/recipes.component';
import {AccountComponent} from './account/account.component';
import {SettingsComponent} from './settings/settings.component';
import {ErrorComponent} from './error/error.component';

/**
 * Routing
 */
import {routing} from './app.routing';


@NgModule({
	imports: [
		BrowserModule,
		// Routing
		routing,
		// Features/Shared
		SharedModule.forRoot(),
		CoreModule.forRoot()
	],
	providers: [PreloadSelectedModulesOnly],
	declarations: [
		AppComponent,
		LayoutComponent,
		HomeComponent,
		NotificationsComponent,
		RecipesComponent,
		AccountComponent,
		SettingsComponent,
		ErrorComponent
	],
	// A list of components that can be bootstrapped.
	// Usually there is only one component in this list,
	// the root component of the application.
	bootstrap: [
		AppComponent
	]
})
export class AppModule {}

@Shinzah
Copy link

Shinzah commented Jan 16, 2017

Could you show your angular-cli.json ?
is app.assets an array ?

@rolandjitsu
Copy link
Author

@Shinzah It is an array, yes. But I cannot see how that would have any impact on AOT.

I do know that I get an error if I add a folder or file that does not exist in the {apps: [{assets: []}]}, but as I said previously, it's a completely different error.

@Splaktar
Copy link
Member

I get the same thing but without the ERROR in providers.forEach is not a function and no other message in its place.

@rolandjitsu
Copy link
Author

I found the issue. It seems like AOT does not like:

const providers = [];

if (someCondition) {
    providers.push({ ...some object });
}

@NgModule({
    providers
})
export class TestModule {}

But it works with:

const providers = [];

if (someCondition) {
    providers.push({ ...some object });
}

@NgModule({
    providers: [
        ...providers
    ]
})
export class TestModule {}

@ghost
Copy link

ghost commented Aug 21, 2019

HI,

i am als0 facing same issue.

unfortunately i have closed issue but still i am facing same issue
#14717

@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 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants