-
Notifications
You must be signed in to change notification settings - Fork 12k
V8.0.0 : loadChildren library module failed : "Error: Runtime compiler is not loaded" on AOT mode #14763
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
Comments
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. |
@trotyl thank you for quick answer, I already use this kind of declaration :export function loadProfile() {
return import('shell').then(m => m.ProfileModule);
}
const routes: Routes = [{
path: '',
canActivate: [SecureGuard],
children: [{
path: '',
component: HomeComponent
}, {
path: 'profile',
loadChildren: loadProfile
}, {
path: '**',
component: HomeComponent
}]
}]; 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 buildconst routes: Routes = [{
path: '',
canActivate: [SecureGuard],
children: [{
path: '',
component: HomeComponent
}, {
path: 'profile',
loadChildren: import('shell').then(m => m.ProfileModule)
}, {
path: '**',
component: HomeComponent
}]
}]; It is an issue with the CLI ? I have to add a bug on the cli project ? |
This is not lazy loading at all, you need to wrap an arrow function. |
Sure, it is a bad copy paste @trotyl const routes: Routes = [{
path: '',
canActivate: [SecureGuard],
children: [{
path: '',
component: HomeComponent
}, {
path: 'profile',
loadChildren: () => import('shell').then(m => m.ProfileModule)
}, {
path: '**',
component: HomeComponent
}]
}]; If I don't declare it as an exported fonction, the build failed, because there is no ng factory for the module |
I create same issue on CLI project : #14700 |
Is |
@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 : "shell": {
"root": "projects/shell",
"sourceRoot": "projects/shell/src",
"projectType": "library",
"prefix": "lib",
"schematics": {
"@schematics/angular:component": {
"styleext": "scss",
"spec": false
},
"@schematics/angular:directive": {
"spec": false
},
"@schematics/angular:modules": {
"spec": false
},
"@schematics/angular:pipe": {
"spec": false
},
"@schematics/angular:service": {
"spec": false
},
"@schematics/angular:class": {
"spec": false
}
},
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/shell/tsconfig.lib.json",
"project": "projects/shell/ng-package.json"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/shell/src/test.ts",
"tsConfig": "projects/shell/tsconfig.spec.json",
"karmaConfig": "projects/shell/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/shell/tsconfig.lib.json",
"projects/shell/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
} |
Sorry for not making it clear, whether it's from "shell": [
"dist/shell"
], It's not the same project, but a separately built library. (Where the source code resides doesn't make any difference) |
ok @trotyl and @alan-agius4 , I already try it yesterday @alan-agius4 : import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { SecureGuard } from 'shell';
import { HomeComponent } from './home/home.component';
import { ProfileWrapperModule } from './shared/profile-wrapper/profile-wrapper.module';
const routes: Routes = [{
path: '',
canActivate: [SecureGuard],
children: [{
path: '',
component: HomeComponent
}, {
path: 'profile',
loadChildren: () => ProfileWrapperModule // For this feature I don't care about lazy loading, I just reuse module for all my portal apps
}, {
path: '**',
component: HomeComponent
}]
}];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { } import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ProfileModule } from 'shell';
@NgModule({
declarations: [],
imports: [
CommonModule,
ProfileModule
]
})
export class ProfileWrapperModule { } 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 |
HI, the It should be: loadChildren: () => import('./shared/profile-wrapper/profile-wrapper.module').then(m => m.ProfileWrapperModule) |
@alan-agius4 , I have the same error than the 2 others ways : import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ProfileModule } from 'shell';
@NgModule({
declarations: [],
imports: [
CommonModule,
ProfileModule
]
})
export class ProfileWrapperModule { } 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('./shared/profile-wrapper.module').then(m => m.ProfileWrapperModule);
}
const routes: Routes = [{
path: '',
canActivate: [SecureGuard],
children: [{
path: '',
component: HomeComponent
}, {
path: 'profile',
loadChildren: loadProfile
}, {
path: '**',
component: HomeComponent
}]
}];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule]
})
export class AppRoutingModule { } Always good on local env, but not on AOT env. (window.webpackJsonp=window.webpackJsonp||[]).push([[5],{Lz8n:function(n,o,r){"use strict";r.r(o),r.d(o,"ProfileWrapperModule",function(){return u});var u=function(){return function(){}}()}}]); And an error appear on the console :
|
Can you try to see if it works if you remove the |
Not possible to build in AOT mode if I pass it directly as an arrow function. |
@robinComa, the following syntax is supported by the AOT compiled loadChildren: () => import('./shared/profile-wrapper/profile-wrapper.module')
.then(m => m.ProfileWrapperModule) Check the lazy loading docs here: https://angular.io/guide/lazy-loading-ngmodules |
Yes that works ! (it was not working on AOT when it is not proxyfied).
loadChildren: () => import('./shared/profile-wrapper/profile-wrapper.module')
.then(m => m.ProfileWrapperModule) import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ProfileModule } from 'shell'; // From Angular project library
@NgModule({
declarations: [],
imports: [
CommonModule,
ProfileModule
]
})
export class ProfileWrapperModule { } Thanks for support ! |
@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? |
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) |
@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. |
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 |
I am also getting same error when adding Dynamic Component. What is the resolution for this? |
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. |
@BerBevans It works like a charm. Thanks for pointing this out. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 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 :
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) :
AppRoutingModule (as an angular project from the same CLI project)
🔥 Exception or Error
🌍 Your Environment
Angular Version:
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
The text was updated successfully, but these errors were encountered: