我试图找到这个错误的任何解决方案,但没有任何对我有用.我有使用Angular-CLI创建的简单Angular2应用程序.当我在浏览器中提供此应用程序时,我收到此错误:EXCEPTION: Uncaught (in promise): Error: Cannot find module '/app/test.module'. 我正在尝试在loadChildren中使用不同的路径:
'/app/test.module'
'./app/test.module'
'./test.module'
'/src/app/test.module'
Run Code Online (Sandbox Code Playgroud)
文件夹
src/
app/
app-routing.module.ts
app.component.ts
app.module.ts
test.component.ts
test.module.ts
Run Code Online (Sandbox Code Playgroud)
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 './app.component';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
RoutingModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule …Run Code Online (Sandbox Code Playgroud) 我正在使用Angular 4构建一个webapp.我有一个顶级路由模块和一个单独的路由模块,用于每个子模块(例如HomeModule).
这是我的顶级路由配置:
export const ROUTES: Routes = [
{path: '', loadChildren: './home#HomeModule'},
{path: '**', component: NotFoundComponent},
];
Run Code Online (Sandbox Code Playgroud)
当我跑ng server,我得到一个奇怪的错误,home找不到该模块.该应用程序无法在浏览器中运行.
奇怪的部分如下:当文件被更改并且webpack重新编译项目时,一切正常并且路由工作.
该错误仅在我运行时出现ng serve.
这是我运行时遇到的错误ng serve,而不是因为文件更改而重新编译项目的错误:
ERROR in Error: Could not resolve module ./home relative to /path/to/my/project/src/app/app.module.ts
at StaticSymbolResolver.getSymbolByModule (/path/to/my/project/node_modules/@angular/compiler/bundles/compiler.umd.js:31884:30)
at StaticReflector.resolveExternalReference (/path/to/my/project/node_modules/@angular/compiler/bundles/compiler.umd.js:30350:62)
at parseLazyRoute (/path/to/my/project/node_modules/@angular/compiler/bundles/compiler.umd.js:28616:55)
at listLazyRoutes (/path/to/my/project/node_modules/@angular/compiler/bundles/compiler.umd.js:28578:36)
at visitLazyRoute (/path/to/my/project/node_modules/@angular/compiler/bundles/compiler.umd.js:29995:47)
at AotCompiler.listLazyRoutes (/path/to/my/project/node_modules/@angular/compiler/bundles/compiler.umd.js:29963:20)
at AngularCompilerProgram.listLazyRoutes (/path/to/my/project/node_modules/@angular/compiler-cli/src/transformers/program.js:157:30)
at Function.NgTools_InternalApi_NG_2.listLazyRoutes (/path/to/my/project/node_modules/@angular/compiler-cli/src/ngtools_api.js:44:36)
at AngularCompilerPlugin._getLazyRoutesFromNgtools (/path/to/my/project/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:247:66)
at Promise.resolve.then.then (/path/to/my/project/node_modules/@ngtools/webpack/src/angular_compiler_plugin.js:538:50)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我已经创建了一个新的应用程序,ng new但是当我尝试使用延迟加载配置模块加载时,我不断收到错误,找不到该模块.
EXCEPTION: Uncaught (in promise): Error: Cannot find module 'app/home/home.module'
Run Code Online (Sandbox Code Playgroud)
"dependencies": {
"@angular/common": "2.0.0-rc.7",
"@angular/compiler": "2.0.0-rc.7",
"@angular/core": "2.0.0-rc.7",
"@angular/forms": "2.0.0-rc.7",
"@angular/http": "2.0.0-rc.7",
"@angular/platform-browser": "2.0.0-rc.7",
"@angular/platform-browser-dynamic": "2.0.0-rc.7",
"@angular/router": "3.0.0-rc.3",
"core-js": "^2.4.1",
"rxjs": "5.0.0-beta.12",
"ts-helpers": "^1.1.1",
"zone.js": "^0.6.21"
},
"devDependencies": {
"@types/jasmine": "^2.2.30",
"angular-cli": "1.0.0-beta.11-webpack.9-4",
"codelyzer": "~0.0.26",
"jasmine-core": "2.4.1",
"jasmine-spec-reporter": "2.5.0",
"karma": "1.2.0",
"karma-chrome-launcher": "^2.0.0",
"karma-cli": "^1.0.1",
"karma-jasmine": "^1.0.2",
"karma-remap-istanbul": "^0.2.1",
"protractor": "4.0.5",
"ts-node": "1.2.1",
"tslint": "3.13.0",
"typescript": "2.0.2"
}
Run Code Online (Sandbox Code Playgroud)
import …Run Code Online (Sandbox Code Playgroud) 我正在学习 Angular 培训课程(使用 Angular 12)。
{ path: 'training', loadChildren: './training/training.module.ts#TrainingModule'},
Run Code Online (Sandbox Code Playgroud)
不管用:
未处理的 Promise 拒绝:找不到模块 './training/training.module.ts' ;区域: ; 任务:Promise.then;值:错误:找不到模块'./training/training.module.ts
我 100% 确定路径来自app-routing.module.ts是正确的(我复制/粘贴了它,以确保)。
然而,之前的课程(由同一位演讲者)让我认为正确的语法应该是:
{path: 'training', loadChildren: () => import('./training/training.module').then(module => module.TrainingModule)}
Run Code Online (Sandbox Code Playgroud)
为什么有这两种可能性?它们在功能上等效吗?我什么时候应该使用哪个?