[英]Typescript compilation error TS2307: Cannot find module with angular2 rc5 and ngModule
I am trying to find out the reason for the following error. 我正在尝试找出以下错误的原因。
app/src/app.module.ts(13,33): error TS2307: Cannot find module 'src/components/test/test.module
I am using Angular2 RC5 and created a feature module and imported it in app.module.ts
file. 我正在使用Angular2 RC5,创建了一个功能模块,并将其导入到
app.module.ts
文件中。 I am using lazy loading of the module with the router. 我正在通过路由器延迟加载模块。
app.module.ts
looks like this app.module.ts
看起来像这样
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { routing } from './app.routes';
/* App Root */
import { AppComponent } from './app.component';
/* Feature module */
import { TestModule } from 'src/components/test/test.module';
@NgModule({
imports: [ BrowserModule, routing ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ],
providers: []
})
export class AppModule { }
test.module.ts
looks like this test.module.ts
看起来像这样
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { TestComponent } from './test.component';
import { routing } from './test.routes';
@NgModule({
imports: [ CommonModule, routing ],
declarations: [ TestComponent ],
providers: []
})
export default class TestModule { }
app.routes.ts
looks like app.routes.ts
看起来像
import { Routes, RouterModule } from '@angular/router';
export const routes: Routes = [
{
path: '',
redirectTo: '/test',
pathMatch: 'full'
},
{
path: 'test',
loadChildren: 'src/components/test/test.module'
}
];
export const routing = RouterModule.forRoot(routes);
test.routes.ts
looks like test.routes.ts
看起来像
import { Routes, RouterModule } from '@angular/router';
import { TestComponent } from './test.component';
const routes: Routes = [
{ path: '',
component: TestComponent }
];
export const routing = RouterModule.forChild(routes);
Above error appears when I try to compile test.module.ts
file with default
keyword. 当我尝试使用
default
关键字编译test.module.ts
文件时,出现上述错误。 If I remove it, error disappears. 如果删除它,错误消失。 but of course, in that case, I won't be able to use lazy loading for feature module.
但是,当然,在那种情况下,我将无法对功能模块使用延迟加载。
Does anyone come across this? 有人遇到吗?
I see multiple errors in your code. 我在您的代码中看到多个错误。 You are importing wrong module in your AppModule.
您在AppModule中导入了错误的模块。 Your export class name of
test.module.ts
is TestModule
, but you are importing DashboardModule
in your AppModule
. 您的
test.module.ts
导出类名称为TestModule
,但是您要在AppModule
中导入DashboardModule
。
Instead of: 代替:
import { DashboardModule } from 'src/components/test/test.module';
You should import: 您应该导入:
import { TestModule } from 'src/components/test/test.module';
And, of course, you need to add TestModule
to your AppModule
imports. 而且,当然,您需要将
TestModule
添加到AppModule
导入中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.