Skip to content

[Feature Request] support dynamically import the bootstrap logic #10166

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

Closed
scott-ho opened this issue Apr 4, 2018 · 3 comments
Closed

[Feature Request] support dynamically import the bootstrap logic #10166

scott-ho opened this issue Apr 4, 2018 · 3 comments

Comments

@scott-ho
Copy link

scott-ho commented Apr 4, 2018

Versions

not related

Repro steps

import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { KeycloakService } from 'xxx';

import { environment } from './environments/environment';

import './rxjs-operators';

if (environment.production) {
  enableProdMode();
}

const keycloakJsonFile = `${environment.baseHref}assets/${environment.env === 'prod' ? 'keycloak-prod.json' : 'keycloak.json'}`;

KeycloakService.init(keycloakJsonFile, {
  onLoad: 'login-required',
  checkLoginIframe: false
}).then(() => {
  KeycloakService.keycloakAuth.onAuthRefreshError = () => {
    KeycloakService.keycloakAuth.logout();
  }

  return import('./app/app.module').then((mod: { AppModule: any}) => {
    const { AppModule } = mod
    platformBrowserDynamic().bootstrapModule(AppModule);
  })
});

Observed behavior

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 (\test\node_modules\@ngtools\webpack\src\entry_resolver.js:131:11)
    at AotPlugin._setupOptions (\test\node_modules\@ngtools\webpack\src\plugin.js:187:50)
    at new AotPlugin (\test\node_modules\@ngtools\webpack\src\plugin.js:31:14)
    at _createAotPlugin (\test\node_modules\@angular\cli\models\webpack-configs\typescript.js:92:16)
    at Object.getNonAotConfig (\test\node_modules\@angular\cli\models\webpack-configs\typescript.js:100:19)
    at NgCliWebpackConfig.buildConfig (\test\node_modules\@angular\cli\models\webpack-config.js:37:37)
    at Class.run (\test\node_modules\@angular\cli\tasks\serve.js:71:98)
    at check_port_1.checkPort.then.port (\test\node_modules\@angular\cli\commands\serve.js:123:26)
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:160:7)

see https://github.com/angular/devkit/blob/master/packages/ngtools/webpack/src/entry_resolver.ts#L91

The _symbolImportLookup only find ImportDeclaration but not ImportCall, so it can't be analyzed.

Desired behavior

Angular-cli support dynamic import of AppModule

@scott-ho
Copy link
Author

related issue #3540 #6930

@mgechev
Copy link
Member

mgechev commented Dec 26, 2018

Let us keep this outside of the CLI for now. You can look into Angular Elements, if you need to bootstrap only part of your page with Angular.

@mgechev mgechev closed this as completed Dec 26, 2018
@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 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants