angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

ng build --aot fails

Open rolandjitsu opened this issue 9 years ago • 8 comments

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.

rolandjitsu avatar Jan 16 '17 11:01 rolandjitsu

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?

filipesilva avatar Jan 16 '17 11:01 filipesilva

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 {}

rolandjitsu avatar Jan 16 '17 11:01 rolandjitsu

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

Shinzah avatar Jan 16 '17 12:01 Shinzah

@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.

rolandjitsu avatar Jan 16 '17 12:01 rolandjitsu

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

Splaktar avatar Jan 18 '17 02:01 Splaktar

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 {}

rolandjitsu avatar Feb 28 '17 14:02 rolandjitsu

HI,

i am als0 facing same issue.

unfortunately i have closed issue but still i am facing same issue https://github.com/angular/angular-cli/issues/14717

ghost avatar Aug 21 '19 06:08 ghost

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.