Angular2延迟加载模块错误'找不到模块'

编程入门 行业动态 更新时间:2024-10-23 15:24:05
本文介绍了Angular2延迟加载模块错误'找不到模块'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试找到针对此错误的任何解决方案,但对我而言没有任何效果.我有使用Angular-CLI创建的简单Angular2应用程序.当我在浏览器中提供此应用程序时,出现此错误:EXCEPTION: Uncaught (in promise): Error: Cannot find module '/app/test.module'.我试图在loadChildren中使用其他路径:

I was trying to find any solution for this error but nothing works for me. I have simple Angular2 App created with Angular-CLI. When I serve this app in browser I'm getting this error: EXCEPTION: Uncaught (in promise): Error: Cannot find module '/app/test.module'. I was trying using different path in loadChildren:

'/app/test.module' './app/test.module' './test.module' '/src/app/test.module'

文件夹

src/ app/ app-routing.module.ts appponent.ts app.module.ts testponent.ts test.module.ts

app.module.ts

import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { HttpModule } from '@angular/http'; import { RoutingModule } from './app-routing.module'; import { AppComponent } from './appponent'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, FormsModule, HttpModule, RoutingModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }

app-routing.module.ts

import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; const routes: Routes = [ { path: '', loadChildren: '/app/test.module' } ]; @NgModule({ imports: [RouterModule.forRoot(routes)], exports: [RouterModule], providers: [] }) export class RoutingModule { }

test.module.ts

import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { CommonModule } from '@angular/common'; import { TestComponent } from './testponent'; export const routes: Routes = [ { path: '', component: TestComponent } ]; @NgModule({ imports: [ CommonModule, RouterModule.forChild(routes) ], exports: [TestComponent], declarations: [TestComponent] }) export default class TestModule { }

堆栈跟踪

error_handler.js:45EXCEPTION: Uncaught (in promise): Error: Cannot find module '/app/test.module'.ErrorHandler.handleError @ error_handler.js:45next @ application_ref.js:273schedulerFn @ async.js:82SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:74onError @ ng_zone.js:120onHandleError @ ng_zone_impl.js:64ZoneDelegate.handleError @ zone.js:207Zone.runGuarded @ zone.js:113_loop_1 @ zone.js:379drainMicroTaskQueue @ zone.js:386 2016-10-08 14:22:50.612 error_handler.js:50ORIGINAL STACKTRACE:ErrorHandler.handleError @ error_handler.js:50next @ application_ref.js:273schedulerFn @ async.js:82SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:74onError @ ng_zone.js:120onHandleError @ ng_zone_impl.js:64ZoneDelegate.handleError @ zone.js:207Zone.runGuarded @ zone.js:113_loop_1 @ zone.js:379drainMicroTaskQueue @ zone.js:386 2016-10-08 14:22:50.613 error_handler.js:51Error: Uncaught (in promise): Error: Cannot find module '/app/test.module'. at resolvePromise (zone.js:429) at zone.js:406 at ZoneDelegate.invoke (zone.js:203) at Object.onInvoke (ng_zone_impl.js:43) at ZoneDelegate.invoke (zone.js:202) at Zone.run (zone.js:96) at zone.js:462 at ZoneDelegate.invokeTask (zone.js:236) at Object.onInvokeTask (ng_zone_impl.js:34) at ZoneDelegate.invokeTask (zone.js:235)ErrorHandler.handleError @ error_handler.js:51next @ application_ref.js:273schedulerFn @ async.js:82SafeSubscriber.__tryOrUnsub @ Subscriber.js:223SafeSubscriber.next @ Subscriber.js:172Subscriber._next @ Subscriber.js:125Subscriber.next @ Subscriber.js:89Subject.next @ Subject.js:55EventEmitter.emit @ async.js:74onError @ ng_zone.js:120onHandleError @ ng_zone_impl.js:64ZoneDelegate.handleError @ zone.js:207Zone.runGuarded @ zone.js:113_loop_1 @ zone.js:379drainMicroTaskQueue @ zone.js:386 2016-10-08 14:22:50.614 zone.js:355Unhandled Promise rejection: Cannot find module '/app/test.module'. ; Zone: angular ; Task: Promise.then ; Value: Error: Cannot find module '/app/test.module'.(…) Error: Cannot find module '/app/test.module'. at webpackEmptyContext (localhost:4200/main.bundle.js:49550:8) at SystemJsNgModuleLoader.loadAndCompile (localhost:4200/main.bundle.js:57952:40) at SystemJsNgModuleLoader.load (localhost:4200/main.bundle.js:57945:60) at RouterConfigLoader.loadModuleFactory (localhost:4200/main.bundle.js:22354:128) at RouterConfigLoader.load (localhost:4200/main.bundle.js:22346:81) at MergeMapSubscriber.project (localhost:4200/main.bundle.js:61105:111) at MergeMapSubscriber._tryNext (localhost:4200/main.bundle.js:32515:27) at MergeMapSubscriber._next (localhost:4200/main.bundle.js:32505:18) at MergeMapSubscriber.Subscriber.next (localhost:4200/main.bundle.js:7085:18) at ScalarObservable._subscribe (localhost:4200/main.bundle.js:48555:24)consoleError @ zone.js:355_loop_1 @ zone.js:382drainMicroTaskQueue @ zone.js:386 2016-10-08 14:22:50.620 zone.js:357Error: Uncaught (in promise): Error: Cannot find module '/app/test.module'.(…)consoleError @ zone.js:357_loop_1 @ zone.js:382drainMicroTaskQueue @ zone.js:386

推荐答案

重新启动ng serve为我工作

更多推荐

Angular2延迟加载模块错误'找不到模块'

本文发布于:2023-11-15 04:04:35,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1590983.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模块   找不到   加载   错误

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!