首页 > 解决方案 > 延迟加载时找不到模块“功能模块的路径”

问题描述

离子延迟加载错误

我在尝试配置延迟加载时遇到以下堆栈跟踪错误:

Error: Uncaught (in promise): Error: Cannot find module 'pages/home/home.module'.
Error: Cannot find module 'pages/home/home.module'.
    at http://localhost:8100/build/main.js:10:9
    at t.invoke (http://localhost:8100/build/polyfills.js:3:14976)
    at Object.onInvoke (http://localhost:8100/build/vendor.js:5134:33)
    at t.invoke (http://localhost:8100/build/polyfills.js:3:14916)
    at r.run (http://localhost:8100/build/polyfills.js:3:10143)
    at http://localhost:8100/build/polyfills.js:3:20242
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
    at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33)
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581)
    at r.runTask (http://localhost:8100/build/polyfills.js:3:10834)
    at c (http://localhost:8100/build/polyfills.js:3:19752)
    at c (http://localhost:8100/build/polyfills.js:3:19461)
    at http://localhost:8100/build/polyfills.js:3:20233
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15660)
    at Object.onInvokeTask (http://localhost:8100/build/vendor.js:5125:33)
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:15581)
    at r.runTask (http://localhost:8100/build/polyfills.js:3:10834)
    at o (http://localhost:8100/build/polyfills.js:3:7894)

配置

Ionic Framework: 3.9.2
Ionic App Scripts: 3.2.1
Angular Core: 5.2.11
Angular Compiler CLI: 5.2.11
Node: 10.12.0
OS Platform: macOS
Navigator Platform: MacIntel
User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36

代码片段

以下是一些文件:

应用程序路由.module.ts

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

const routes: Routes = [
    { path: 'home', loadChildren: "pages/home/home.module#HomePageModule" },
    { path: 'form', loadChildren: "pages/form/form.module#FormPageModule" },
    { path: '',  redirectTo: '/home',  pathMatch: 'full' }
];

@NgModule({
    imports: [ RouterModule.forRoot(routes, {
        enableTracing: true
    }) ],
    exports: [ RouterModule ]
})

export class AppRoutingModule { }

我尝试了 的值的变化loadChildren,例如:

pages/home/home.module#HomePageModule

./home/home.module#HomePageModule

../pages/home/home.module#HomePageModule

注意事项

不知道这里还能做什么,我按照 ionic 文档中关于延迟加载的说明进行操作,并阅读了 Angular 文档以了解延迟加载。

问题

  1. 如何修复“找不到模块”错误?我知道文件在那里,但 Ionic/Angular 无法找到模块文件的位置。

  2. 我真的需要像angular-router-loader这样的外部依赖项来启用 angular 从基于字符串的文件路径引用中加载模块吗?

Github 存储库

要重现该错误,请查看以下存储库:

https://github.com/darrensapalo/ionic-lazy-loading-error

标签: angularionic3lazy-loading

解决方案


推荐阅读