Repository navigation
Closed
Description
🐞 bug report
Affected Package
The issue is caused by package @angular/compiler and/or @angular/core and/or @angular/router
Is this a regression?
Yes, the previous version in which this bug was not present was: 7.2.1
Description
I try to load a project library (named shell) as a route "loadChildren", with 2 différents option :
- loadChildren: () => import('shell').then(m => m.ProfileModule)
- loadChildren: () => ProfileModule
This 2 ways work correctly on dev mode, but failed on AOT builded mode with an error message. And the route is not loaded.
🔬 Minimal Reproduction
ProfileModule (as an angular library named "shell" on the CLI project) :
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatIconModule } from '@angular/material/icon';
import { MatListModule } from '@angular/material/list';
import { FlexLayoutModule } from '@angular/flex-layout';
import { ProfileComponent } from './profile/profile.component';
import { TranslateModule } from '../translate/translate.module';
import { GhostModule } from '../ghost/ghost.module';
import { DataModule } from '../data/data.module';
import { ProfileRoutingModule } from './profile-routing.module';
import { ProfileCardComponent } from './profile-card/profile-card.component';
@NgModule({
declarations: [
ProfileComponent,
ProfileCardComponent
],
imports: [
CommonModule,
MatCardModule,
MatListModule,
MatButtonModule,
MatIconModule,
TranslateModule,
FlexLayoutModule,
GhostModule,
DataModule,
ProfileRoutingModule
],
exports: [
ProfileCardComponent
]
})
export class ProfileModule { }AppRoutingModule (as an angular project from the same CLI project)
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SecureGuard } from 'shell';
import { HomeComponent } from './home/home.component';
export function loadProfile() {
return import('shell').then(m => m.ProfileModule);
}
const routes: Routes = [{
path: '',
canActivate: [SecureGuard],
children: [{
path: '',
component: HomeComponent
}, {
path: 'profile',
loadChildren: loadProfile // Here the error at runtime, the error message appear when I go to /profile
}, {
path: '**',
component: HomeComponent
}]
}];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { }🔥 Exception or Error
Uncaught Error: Uncaught (in promise): Error: Runtime compiler is not loaded
Error: Runtime compiler is not loaded
at e.Jr (main.41ff3398f5c3f189c836.js:1)
at t.project (main.41ff3398f5c3f189c836.js:1)
at t._tryNext (main.41ff3398f5c3f189c836.js:1)
at t._next (main.41ff3398f5c3f189c836.js:1)
at t.next (main.41ff3398f5c3f189c836.js:1)
at e._subscribe (main.41ff3398f5c3f189c836.js:1)
at e._trySubscribe (main.41ff3398f5c3f189c836.js:1)
at e.subscribe (main.41ff3398f5c3f189c836.js:1)
at e.call (main.41ff3398f5c3f189c836.js:1)
at e.subscribe (main.41ff3398f5c3f189c836.js:1)
at Z (polyfills.06b93379260cc1d8e708.js:1)
at Z (polyfills.06b93379260cc1d8e708.js:1)
at polyfills.06b93379260cc1d8e708.js:1
at e.invokeTask (polyfills.06b93379260cc1d8e708.js:1)
at Object.onInvokeTask (main.41ff3398f5c3f189c836.js:1)
at e.invokeTask (polyfills.06b93379260cc1d8e708.js:1)
at t.runTask (polyfills.06b93379260cc1d8e708.js:1)
at g (polyfills.06b93379260cc1d8e708.js:1)
at t.invokeTask [as invoke] (polyfills.06b93379260cc1d8e708.js:1)
at m (polyfills.06b93379260cc1d8e708.js:1)
🌍 Your Environment
Angular Version:
Angular CLI: 8.0.1
Node: 12.4.0
OS: darwin x64
Angular: 8.0.0
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, material, material-moment-adapter
... platform-browser, platform-browser-dynamic, router
... service-worker
Package Version
------------------------------------------------------------
@angular-devkit/architect 0.800.1
@angular-devkit/build-angular 0.800.1
@angular-devkit/build-ng-packagr 0.800.1
@angular-devkit/build-optimizer 0.800.1
@angular-devkit/build-webpack 0.800.1
@angular-devkit/core 8.0.1
@angular-devkit/schematics 8.0.1
@angular/cli 8.0.1
@angular/flex-layout 8.0.0-beta.26
@angular/pwa 0.800.1
@ngtools/json-schema 1.1.0
@ngtools/webpack 8.0.1
@schematics/angular 8.0.1
@schematics/update 0.800.1
ng-packagr 5.2.0
rxjs 6.5.2
typescript 3.4.5
webpack 4.30.0
Anything else relevant?
I try to use on different CLI projects a Profile module from a CLI library (all on the same CLI project). This is not possible since angular 8.0.0
Reacted by Junior Rojas, Anatolii Lakhno, Chris Marx, enima-dema and Martin Pultz
Metadata
Metadata
Assignees
Labels
No labels
Activity
trotyl commentedon Jun 7, 2019
It's a known limitation:
See https://angular.io/guide/deprecations#loadchildren-string-syntax for more information.
If you believe this is worthing implementing please consider open a feature request to Angular CLI.
robinComa commentedon Jun 7, 2019
@trotyl thank you for quick answer,
I already use this kind of declaration :
If I declare it like that, I have a build issue with ng factory don't exist (I cannot use the Ivy build system, they are issue with the library build
It is an issue with the CLI ? I have to add a bug on the cli project ?
trotyl commentedon Jun 7, 2019
This is not lazy loading at all, you need to wrap an arrow function.
robinComa commentedon Jun 7, 2019
Sure, it is a bad copy paste @trotyl
If I don't declare it as an exported fonction, the build failed, because there is no ng factory for the module
robinComa commentedon Jun 7, 2019
I create same issue on CLI project : #14700
trotyl commentedon Jun 7, 2019
Is
shellalso a copy-paste issue? You cannot load an NgModule fromnode_modules, it must belong to your project.robinComa commentedon Jun 7, 2019
@trotyl, shell is a library from the same project, here the tsconfig file, so it is not a node_module, but an angular library :
{ "compileOnSave": false, "compilerOptions": { "baseUrl": "./", "outDir": "./dist/out-tsc", "sourceMap": true, "declaration": false, "module": "esNext", "moduleResolution": "node", "emitDecoratorMetadata": true, "experimentalDecorators": true, "importHelpers": true, "target": "es5", "typeRoots": [ "node_modules/@types" ], "lib": [ "es2018", "dom" ], "paths": { "shell": [ "dist/shell" ], "shell/*": [ "dist/shell/*" ] } } }and the piece of angular.json about the shell library :
trotyl commentedon Jun 7, 2019
Sorry for not making it clear, whether it's from
node_modulesdoesn't matter, from your configuration:It's not the same project, but a separately built library. (Where the source code resides doesn't make any difference)
robinComa commentedon Jun 7, 2019
ok @trotyl and @alan-agius4 , I already try it yesterday @alan-agius4 :
And it produce the same error
@alan-agius4 , you can close other issue if you want
For this 2 ways, that works on dev mode, build AOT is ok, but it is broke on runtime when I try to load the module
alan-agius4 commentedon Jun 11, 2019
HI, the
loadChildrensyntax is your example above is not correct.It should be:
robinComa commentedon Jun 13, 2019
@alan-agius4 , I have the same error than the 2 others ways :
Always good on local env, but not on AOT env.
When a click on the menu to go to my lazy loaded route, the lazy script .js is loaded but it seems to be empty :
And an error appear on the console :
alan-agius4 commentedon Jun 13, 2019
Can you try to see if it works if you remove the
loadProfileand pass an arrow function directly toloadChildrenas per my previous example?robinComa commentedon Jun 13, 2019
Not possible to build in AOT mode if I pass it directly as an arrow function.
alan-agius4 commentedon Jun 13, 2019
@robinComa, the following syntax is supported by the AOT compiled
Check the lazy loading docs here: https://angular.io/guide/lazy-loading-ngmodules
robinComa commentedon Jun 13, 2019
Yes that works ! (it was not working on AOT when it is not proxyfied).
To conclude, the solution to load a library module is :
Thanks for support !
CSchulz commentedon Jul 29, 2019
@alan-agius4 Is support for other import variants planned? I didn't find any issue stating support for different kinds of imports for lazy children.
It seems lazy children are limited to the application type and do not support libraries, right?
We have our router module in one library, because the setup is always the same and we don't want to duplicate it for every application.
alan-agius4 commentedon Jul 29, 2019
Hi @CSchulz, that is correct, lazy loading routes are not supported in libraries, and at the moment there are no concrete plans yet to support this feature.
There is a greater discussion around this here: #6373 (comment)
CSchulz commentedon Jul 29, 2019
@alan-agius4 Thanks for your fast reply. I have seen that discussion.
To support libraries the libraries needs to provide the factories itself? I have tried to investigate what is missing for supporting it.
82antu commentedon Sep 8, 2019
I know it's closed but, M I the only one that are is not able to let it work on AOT or PROD ?? proxyfied or not, inside the project or from node_modules AOT (or PROD) compilation always give me "Error: Runtime compiler is not loaded".
Thanks in advance
akvaliya commentedon Sep 20, 2019
I am also getting same error when adding Dynamic Component. What is the resolution for this?
BerBevans commentedon Oct 4, 2019
Anyone still having this problem, you might be having the same problem as me and I found the answer here:
In summary, I was using backticks rather than single quotes when giving the path to the module I wanted to load.
phetw commentedon Oct 9, 2019
@BerBevans It works like a charm. Thanks for pointing this out.
angular-automatic-lock-bot commentedon Nov 9, 2019
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.