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

lazy loading chunks not built if bootstrap is not in main.ts file #12025

Closed
devversion opened this issue Aug 28, 2018 · 3 comments · Fixed by #12559
Closed

lazy loading chunks not built if bootstrap is not in main.ts file #12025

devversion opened this issue Aug 28, 2018 · 3 comments · Fixed by #12559
Labels
area: devkit/build-angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Milestone

Comments

@devversion
Copy link
Member

Currently if people want to use lazy loading within Angular CLI projects and their bootstrap code is not placed inside of the $PROJECT_ROOT/main.ts file, the chunks for the lazy-loading module are not being generated.

This leads to JIT runtime errors that indicate that the lazy module couldn't be found.

core.js:1673 ERROR Error: Uncaught (in promise): Error: Cannot find module 'lazy/slider.module'
Error: Cannot find module 'lazy/slider.module'
    at $_lazy_route_resource lazy namespace object:5

Moving the boostrap call to the main.ts file fixes this issue (credits to @filipesilva for this finding)

--

It would be good to have some warning or note that implicates that lazy modules won't be detected if the bootstrap call is placed somewhere else.

Issue demonstration: https://github.com/DevVersion/lazy-load-test-cli

cc. @filipesilva

@alan-agius4 alan-agius4 added freq1: low Only reported by a handful of users who observe it rarely severity3: broken area: devkit/build-angular labels Aug 28, 2018
@ngbot ngbot bot added this to the needsTriage milestone Aug 28, 2018
@ngbot ngbot bot modified the milestones: needsTriage, Backlog Aug 30, 2018
@santiago-elustondo
Copy link

Is there a workaround? I need to call bootstrapModule() in a different file.

@mascarenhas
Copy link

mascarenhas commented Sep 11, 2018

You can get around this by adding an entryModule key in the application's angularCompilerOptions object in the tsconfig.json file pointing to your main module, like this: "entryModule": "./app/app.module#AppModule".

That this is failing at runtime instead of throwing a compiler error is probably a bug in the Angular CLI, the relevant function in the Angular CLI source is bailing out with null in some cases (

if (bootstrap.length != 1) {
) and throwing an error in others.

kyliau pushed a commit that referenced this issue Oct 23, 2018
…disabled

At the moment this will cause a runtime error instead. With this change a warning will be shown during the build.

Closes #12238 and Closes #12025
kyliau pushed a commit that referenced this issue Oct 23, 2018
…disabled

At the moment this will cause a runtime error instead. With this change a warning will be shown during the build.

Closes #12238 and Closes #12025
@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 8, 2019
ikjelle pushed a commit to ikjelle/angular-cli that referenced this issue Mar 26, 2024
…disabled

At the moment this will cause a runtime error instead. With this change a warning will be shown during the build.

Closes angular#12238 and Closes angular#12025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: devkit/build-angular freq1: low Only reported by a handful of users who observe it rarely severity3: broken type: bug/fix
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants