gpt4 book ai didi

angular - 异常 : Uncaught (in promise): Error: Cannot find module 'app/home/home.module'

转载 作者:太空狗 更新时间:2023-10-29 17:00:56 26 4
gpt4 key购买 nike

我正在尝试使用路由器延迟加载 Angular 2 模块,但出现此错误:

error_handler.js:50 EXCEPTION: Uncaught (in promise): Error: Cannot find module 'app/home/home.module'

我尝试了所有似乎对其他人都有效的答案,比如这个似乎是每个面临这个问题的解决方案,但对我不起作用 Lazy loading in Angular2 RC7 and angular-cli webpack

这是我的代码:app.module

import { MediatorService } from './home/mediator.service';
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';

import { AppComponent } from './app.component';


import appRoutes from "./app.routes";


@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
appRoutes
],
providers: [MediatorService],
bootstrap: [AppComponent]
})
export class AppModule { }

app.routes

import { RouterModule } from '@angular/router';

const routes = [
{path : '', loadChildren: './home/home.module#HomeModule'},
{path: 'devis', loadChildren: './forms/forms.module#FormsModule'}
];

export default RouterModule.forRoot(routes);

home.module

import {NgModule} from "@angular/core";
import {CommonModule} from "@angular/common";
import homeRoutes from "./home.routes";

@NgModule({
imports:[CommonModule, homeRoutes],
declarations: [HomeComponent]
})
export default class HomeModule{}

home.routes

import {RouterModule} from "@angular/router";
import {HomeComponent} from "./home.component";
const routes = [
{path: '', component: HomeComponent}
];

export default RouterModule.forChild(routes);

Package.json

{
"name": "insurance",
"version": "0.0.0",
"license": "MIT",
"angular-cli": {},
"scripts": {
"ng": "ng",
"start": "ng serve",
"lint": "tslint \"src/**/*.ts\"",
"test": "ng test",
"pree2e": "webdriver-manager update --standalone false --gecko false",
"e2e": "protractor"
},
"private": true,
"dependencies": {
"@angular/common": "^2.3.1",
"@angular/compiler": "^2.3.1",
"@angular/core": "^2.3.1",
"@angular/forms": "^2.3.1",
"@angular/http": "^2.3.1",
"@angular/platform-browser": "^2.3.1",
"@angular/platform-browser-dynamic": "^2.3.1",
"@angular/router": "^3.3.1",
"bootstrap": "^4.0.0-alpha.5",
"core-js": "^2.4.1",
"font-awesome": "^4.7.0",
"rxjs": "^5.0.1",
"ts-helpers": "^1.1.1",
"zone.js": "^0.7.2"
},
"devDependencies": {
"@angular/compiler-cli": "^2.3.1",
"@types/jasmine": "2.5.38",
"@types/jquery": "^2.0.34",
"@types/node": "^6.0.42",
"angular-cli": "1.0.0-beta.24",
"codelyzer": "~2.0.0-beta.1",
"jasmine-core": "2.5.2",
"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.13",
"ts-node": "1.2.1",
"tslint": "^4.0.2",
"typescript": "~2.0.3"
}
}

更新

我设法让它在 plunker 上运行

https://plnkr.co/edit/uLxmxDIeCdDzxbFjYQS7?p=preview

但是我的机器上还是什么都没有!!!!

更新

我安装了一个新的虚拟机ubuntu 16.04我有同样的问题!可能是因为模块的版本,我的意思是那些在 package.json 上的?我如何找出 plunker 中使用的版本,因为它在那里工作。

最佳答案

对于 Angular 8 和 9,延迟加载声明发生了变化。由于Angular 8引入了新的推荐模块加载方式,之前懒加载模块的默认方式是指定模块的字符串路径:

{ path: 'auth', loadChildren: 'src/app/auth/auth.module#AuthModule' }

导入模块的方式改为动态导入。动态导入是基于 promise 的,让您可以访问模块,可以在其中调用模块的类。因此,您的导入现在应该更改为:

  { path: 'auth', loadChildren: () => import('src/app/auth/auth.module').then(m => m.AuthModule) }

关于angular - 异常 : Uncaught (in promise): Error: Cannot find module 'app/home/home.module' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41396839/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com