angular - 延迟加载时找不到模块“功能模块的路径”
问题描述
离子延迟加载错误
我在尝试配置延迟加载时遇到以下堆栈跟踪错误:
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
代码片段
以下是一些文件:
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
注意事项
- 在我的 上
app/app.module.ts
,我已经不导入要延迟加载的模块。 - 在我的 上
app/app.component.ts
,我使用对我的HomePage
模块的字符串引用。 - 在我
app/app-routing.module.ts
的,路由使用loadChildren
引用我的模块的文件路径。 - App 模块使用,而文件夹
RouterModule.forRoot
中的功能模块使用.pages
RouterModule.forChild
不知道这里还能做什么,我按照 ionic 文档中关于延迟加载的说明进行操作,并阅读了 Angular 文档以了解延迟加载。
问题
如何修复“找不到模块”错误?我知道文件在那里,但 Ionic/Angular 无法找到模块文件的位置。
我真的需要像angular-router-loader这样的外部依赖项来启用 angular 从基于字符串的文件路径引用中加载模块吗?
Github 存储库
要重现该错误,请查看以下存储库:
解决方案
推荐阅读
- java - MapStruct 中的通用 Mapper 函数
- powerbi - PowerBI仪表板中一个图表中的多个小条形图
- c# - C# 命名空间只能访问使用 static 关键字声明的方法吗?
- c++ - 当我第二次调用函数两次时,函数运行时我无法输入
- python - “未经授权的 WebHook 回调通道”Google Api 响应,即使 Heroku Web 应用程序域已验证
- javascript - 遍历嵌套对象以找到关键属性并返回该对象 - Javascript
- sql - 从 Postgresql 中的数据插入字典
- java - SammysRentalPrice JOptionPane
- node.js - 更新节点中的会话变量
- java - Windows 10 上的 Keycloak 启动时异常