bug(webpack): Webpack do not find bootstrap code if app is bootstrapped asynchronously
OS?
Mac OSX (Sierra)
Versions.
angular-cli: 1.0.0-beta.22-1
node: 6.5.0
os: darwin x64
Repro steps.
- Configure i18n according to angular's cookbook
- run
ng serve
The log given by the failure.
Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
Error: Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
at Object.resolveEntryModuleFromMain (/Users/cgcladera/Projects/ws-v4/webcastudio-wms/node_modules/@ngtools/webpack/src/entry_resolver.js:121:15)
at AotPlugin._setupOptions (/Users/cgcladera/Projects/ws-v4/webcastudio-wms/node_modules/@ngtools/webpack/src/plugin.js:129:58)
at new AotPlugin (/Users/cgcladera/Projects/ws-v4/webcastudio-wms/node_modules/@ngtools/webpack/src/plugin.js:37:14)
at Object.exports.getWebpackNonAotConfigPartial (/Users/cgcladera/Projects/ws-v4/webcastudio-wms/node_modules/angular-cli/models/webpack-build-typescript.js:20:13)
at new NgCliWebpackConfig (/Users/cgcladera/Projects/ws-v4/webcastudio-wms/node_modules/angular-cli/models/webpack-config.js:23:42)
at Class.run (/Users/cgcladera/Projects/ws-v4/webcastudio-wms/node_modules/angular-cli/tasks/serve-webpack.js:20:22)
at /Users/cgcladera/Projects/ws-v4/webcastudio-wms/node_modules/angular-cli/commands/serve.js:102:26
at process._tickCallback (internal/process/next_tick.js:103:7)
Mention any other details that might be useful.
I'm having this issue since I upgraded my project from beta.18 to beta.22.
After following i18n documentation your main.ts gets like this:
import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import {
enableProdMode
} from '@angular/core';
import { AppModule } from './app/';
import {environment} from './environments/environment';
import {getTranslationProviders} from './app/i18n-providers';
if (environment.production) {
enableProdMode();
}
getTranslationProviders(environment.i18n.supportedLanguages).then(providers => {
const options = { providers: providers };
platformBrowserDynamic().bootstrapModule(AppModule, options);
});
The problem seems to be with bootstrapping the application asynchronously. If I do not get the translation providers and directly bootstrap the module ng serve runs normally.
Same here:
OS?
Debian 8
Versions.
angular-cli: 1.0.0-beta.22-1 node: 6.9.2 os: linux x64
Repro steps.
Was this an app that wasn't created using the CLI? What change did you do on your code? etc. Update to beta.22-1
The log given by the failure.
Error: Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options. at Object.resolveEntryModuleFromMain (/home/user/workspace/project/node_modules/@ngtools/webpack/src/entry_resolver.js:121:15) at AotPlugin._setupOptions (/home/user/workspace/project/node_modules/@ngtools/webpack/src/plugin.js:129:58) at new AotPlugin (/home/user/workspace/project/node_modules/@ngtools/webpack/src/plugin.js:37:14) at Object.exports.getWebpackNonAotConfigPartial (/home/user/workspace/project/node_modules/angular-cli/models/webpack-build-typescript.js:20:13) at new NgCliWebpackConfig (/home/user/workspace/project/node_modules/angular-cli/models/webpack-config.js:23:42) at Class.run (/home/user/workspace/project/node_modules/angular-cli/tasks/serve-webpack.js:20:22) at /home/user/workspace/project/node_modules/angular-cli/commands/serve.js:102:26 at process._tickCallback (internal/process/next_tick.js:103:7)
Mention any other details that might be useful.
import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { environment } from './environments/environment';
import { AppModule } from './app/';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule)
.then(success => console.log(`Bootstrap success`))
.catch(err => console.error(err));
I guess the .then() function is the reason for this behaviour. If I delete the .then and .catch functions it works as expected. Is there another suggested way for handling bootstrapping errors?
I think #2887 is about the same error and proposes different work arounds.
Upgraded to beta.23 and still having this issue
I'm getting this on my build machine. Same problem.
Same for me.
Same for me. +1 for a bugfix.
beta.24. Getting the same error when coded the AppModule and AppComponent inside the main.ts.
Didn't have this issue in beta.21.
Hit the same issue, but after I removed
.then(success => console.log(`Bootstrap success`))
.catch(err => console.error(err));
from
platformBrowserDynamic().bootstrapModule(AppModule)
the issue disappeared.
@Anastasoff I'm getting the same error #3744 without using then().
Same problem because I use Polymer with angular and I need to bootstrap my app like that:
document.addEventListener('WebComponentsReady', function() {
platformBrowserDynamic().bootstrapModule(AppModule);
});
I write "entryModule: 'app/app.module#AppModule'" to the AotPlugin options in "webpack-build-typescript.js", it works. So give a way to config the entryModule? :)
update to "version": "1.0.0-beta.24", and the same problem with
platformBrowserDynamic().bootstrapModule(AppModule);
angular-cli: 1.0.0-beta.24
node: 7.3.0
os: win32 x64
@angular/common: 2.4.1
@angular/compiler: 2.4.1
@angular/core: 2.4.1
@angular/forms: 2.4.1
@angular/http: 2.4.1
@angular/platform-browser: 2.4.1
@angular/platform-browser-dynamic: 2.4.1
@angular/router: 3.4.1
@angular/compiler-cli: 2.4.1
solved! :)
when move files in webstorm, refact with extension and this is the problem.
change this:
import { AppModule } from 'app/app.module.ts';
to:
import { AppModule } from 'app/app.module';
same for me.
This AoT detection bug should have been solved in a post beta.24 release. See #2887.
For now, you can use following horrible hack snippet. You have to add following code PAST YOUR bootstrap sequence:
// <-- your custom init platformBrowserDynamic().bootstrapModule(AppModule) is located here
// HACK: horrible workaround for AoT bootstrap detection bug
let hackThis = false;
if (hackThis) {
platformBrowserDynamic().bootstrapModule(AppModule);
}
@yuri1969 doesn't work for me. Following is the bootstrap code. `import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment';
import { BAppModule } from './bApp/'; import { BSystemService } from './bGlobal/BSystemService';
let bSystemService : BSystemService = BSystemService.getInstance();
if (environment.production) { enableProdMode(); }
if(bSystemService.deviceType == 'MOBILE'){ document.addEventListener("deviceready", function() { platformBrowserDynamic().bootstrapModule(BAppModule); }, false); } else{ platformBrowserDynamic().bootstrapModule(BAppModule); }
let hackThis = false; if (hackThis) { platformBrowserDynamic().bootstrapModule(BAppModule); } `
Error
Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
Error: Tried to find bootstrap code, but could not. Specify either statically analyzable bootstrap code or pass in an entryModule to the plugins options.
at Object.resolveEntryModuleFromMain (/home/jwuser/projects/Repo/bitbucket/ghs/node_modules/@ngtools/webpack/src/entry_resolver.js:121:15)
at AotPlugin._setupOptions (/home/jwuser/projects/Repo/bitbucket/ghs/node_modules/@ngtools/webpack/src/plugin.js:158:54)
at new AotPlugin (/home/jwuser/projects/Repo/bitbucket/ghs/node_modules/@ngtools/webpack/src/plugin.js:17:14)
at Object.exports.getWebpackNonAotConfigPartial (/home/jwuser/projects/Repo/bitbucket/ghs/node_modules/angular-cli/models/webpack-build-typescript.js:20:13)
at new NgCliWebpackConfig (/home/jwuser/projects/Repo/bitbucket/ghs/node_modules/angular-cli/models/webpack-config.js:26:42)
at Class.run (/home/jwuser/projects/Repo/bitbucket/ghs/node_modules/angular-cli/tasks/serve-webpack.js:20:22)
at /home/jwuser/projects/Repo/bitbucket/ghs/node_modules/angular-cli/commands/serve.js:108:26
at process._tickCallback (internal/process/next_tick.js:103:7)
Same here.
I used to get things works based on @yuri1969 "hack" but since this morning, i get the same error as @tulinisarg
See code below.
import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment'; import { AppModule } from './app/app.module';
import { getTranslationProviders } from './app/i18n-provider';
if (environment.production) { enableProdMode(); }
getTranslationProviders().then(providers => { const options = { providers }; platformBrowserDynamic().bootstrapModule(AppModule, options);
});
let hackThis = false; if (hackThis) { platformBrowserDynamic().bootstrapModule(AppModule); }
There is my package.json :
"dependencies": { "@angular/common": "^2.4.0", "@angular/compiler": "^2.4.0", "@angular/compiler-cli": "^2.4.0", "@angular/core": "^2.4.0", "@angular/forms": "^2.4.0", "@angular/http": "^2.4.0", "@angular/platform-browser": "^2.4.0", "@angular/platform-browser-dynamic": "^2.4.0", "@angular/platform-server": "^2.4.0", "@angular/router": "~3.4.0", "@types/lodash": "^4.14.39", "@types/rx": "^2.5.33", "concurrently": "^3.1.0", "core-js": "^2.4.1", "lodash": "^4.17.2", "rx": "4.1.0", "ts-helpers": "^1.1.1", "zone.js": "^0.7.2" }, "devDependencies": { "@reactivex/rxjs": "^5.0.0-rc.4", "@types/jasmine": "^2.2.30", "@types/node": "^6.0.42", "angular-cli": "1.0.0-beta.24", "codelyzer": "1.0.0-beta.1", "graceful-fs": "4.1.11", "jasmine-core": "2.4.1", "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.9", "ts-node": "1.2.1", "tslint": "3.13.0", "typescript": "~2.0.3" }
@yroul Can you try writing the bootstrap code in a function? It works for me.
here are the dependencies
"dependencies": {
"@angular/common": "^2.4.1",
"@angular/compiler": "^2.4.1",
"@angular/core": "^2.4.1",
"@angular/forms": "^2.4.1",
"@angular/http": "^2.4.1",
"@angular/platform-browser": "^2.4.1",
"@angular/platform-browser-dynamic": "^2.4.1",
"@angular/router": "^3.4.1",
"angular2-onsenui": "^1.0.0-rc.3",
"core-js": "^2.4.1",
"onsenui": "^2.0.5",
"rxjs": "^5.0.2",
"ts-helpers": "^1.1.2",
"zone.js": "^0.7.5"
}
main.ts
`import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment';
import { BAppModule } from './bApp/'; import { BSystemService } from './bGlobal/BSystemService';
let bSystemService: BSystemService = BSystemService.getInstance();
if (environment.production) { enableProdMode(); }
if (bSystemService.deviceType == 'MOBILE') { document.addEventListener('deviceready', function() { bootstrapNow(); }); } else { bootstrapNow(); }
function bootstrapNow() { platformBrowserDynamic().bootstrapModule(BAppModule); }`
@tulinisarg @yroul I've tried that hack of mine on beta.24. It needs retesting on any newer Angular-cli.
I can look into it later.
@tulinisarg @yuri1969
I was able to make it work using @tulinisarg method (putting bootstrap code in function) or by simply removing @yuri1969 's hack.
Here is my main.ts (without yuri's hack)
import './polyfills.ts';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; import { enableProdMode } from '@angular/core'; import { environment } from './environments/environment'; import { AppModule } from './app/app.module';
import { getTranslationProviders } from './app/i18n-provider';
if (environment.production) { enableProdMode(); } /** *
- It looks like the "hack" below does not work anymore since 01/16/2017
- Disable I18n provider and async loading */ getTranslationProviders().then(providers => { const options = { providers }; platformBrowserDynamic().bootstrapModule(AppModule, options);
});
my package.json
"dependencies": { "@angular/common": "^2.4.0", "@angular/compiler": "^2.4.0", "@angular/compiler-cli": "^2.4.0", "@angular/core": "^2.4.0", "@angular/forms": "^2.4.0", "@angular/http": "^2.4.0", "@angular/platform-browser": "^2.4.0", "@angular/platform-browser-dynamic": "^2.4.0", "@angular/platform-server": "^2.4.0", "@angular/router": "~3.4.0", "@types/lodash": "^4.14.39", "@types/rx": "^2.5.33", "concurrently": "^3.1.0", "core-js": "^2.4.1", "lodash": "^4.17.2", "rx": "4.1.0", "ts-helpers": "^1.1.1", "zone.js": "^0.7.2" }, "devDependencies": { "@reactivex/rxjs": "^5.0.0-rc.4", "@types/jasmine": "^2.2.30", "@types/node": "^6.0.42", "angular-cli": "1.0.0-beta.24", "codelyzer": "1.0.0-beta.1", "graceful-fs": "4.1.11", "jasmine-core": "2.4.1", "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.9", "ts-node": "1.2.1", "tslint": "3.13.0", "typescript": "~2.0.3" }
Then
rm -rf node_modules && npm cache clean && npm install && ng build --prod