简体   繁体   English

打字稿编译错误TS2307:找不到带有angular2 rc5和ngModule的模块

[英]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.

相关问题 TS2307:在 TypeScript 上导入 Angular2 时找不到模块“angular2/core” - TS2307: Cannot find module 'angular2/core' while importing Angular2 on TypeScript 打字稿编译器错误 TS2307:找不到模块“jquery” - Typescript Compiler error TS2307: Cannot find module 'jquery' TS2307:找不到模块“角度” - TS2307: Cannot find module 'angular' Typescript 找不到本地 es6 模块; 错误 TS2307:找不到模块 - Typescript cannot find local es6 module; error TS2307: Cannot find module 错误 TS2307:找不到模块(外部、私有模块) - error TS2307: Cannot find module (external, private module) 运行时错误:错误TS2307:找不到模块“传单” - Runtime Error: error TS2307: Cannot find module 'leaflet' TS2307:找不到模块“计算器” - TS2307: Cannot find module 'calculator' TypeScript + moment.js:错误TS2307:找不到模块'时刻' - TypeScript + moment.js: error TS2307: Cannot find module 'moment' 在 Angular 7 中实现 redux 会出现错误 TS2307:找不到模块“redux”。 错误 - Implementing redux in Angular 7 gives error TS2307: Cannot find module 'redux'. error 错误:找不到模块“nexmo”和错误 TS2307:找不到模块 nexmo - Error: Cannot find module 'nexmo' & error TS2307: Cannot find module nexmo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM