简体   繁体   English

找不到模块延迟预加载角度路由

[英]cannot find module lazy preload Angular Routing

I have looked at all the SO questions about this already, and still can't figure it out. 我已经看过所有关于此的SO问题,但仍然无法解决。

I'm preloading a module, and I'm getting the error: 我正在预加载模块,但出现错误:

ERROR Error: Uncaught (in promise): Error: Cannot find module './results/results.module' Error: Cannot find module './results/results.module' at :4200/main.js:48:11 [angular] 错误错误:未捕获(承诺):错误:找不到模块'./results.results.module'错误:找不到模块'./results.results.module'在:4200 / main.js:48:11 [角度]

I've triple checked the spelling, and even made a small app to try and recreate it, but it works perfectly, I'm not sure what I'm doing wrong. 我已经对拼写进行了三重检查,甚至制作了一个小应用程序尝试重新创建它,但是它运行良好,我不确定自己做错了什么。 Unfortunately I cannot post a live example for confidentiality. 不幸的是,我不能发布一个真实的机密示例。

AppRoutingModule AppRoutingModule

import { NgModule } from '@angular/core';
import { PlanComponent } from 'app/plan/plan.component';
import { MaintenanceComponent } from './maintenance/maintenance/maintenance.component';
import { Routes, RouterModule, PreloadAllModules } from '@angular/router';

const appRoutes: Routes = [
    { path: '', redirectTo: '/plan', pathMatch: 'full' },
    { path: 'plan', component: PlanComponent },
    { path: 'maintenance', component: MaintenanceComponent },

    // this is the failing module
    { path: 'results', loadChildren: './results/results.module#ResultsModule' },
];

@NgModule({
    imports: [
        RouterModule.forRoot(appRoutes, {
            preloadingStrategy: PreloadAllModules
        })
    ],
    exports: [RouterModule]
})
export class AppRoutingModule {}

AppModule 的AppModule

import { NgModule, Injector } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { AppRoutingModule } from 'app/app-routing.module';

... other components not including the lazy loaded module

...
imports: [
        BrowserModule,
        AppRoutingModule,
        FormsModule,
        HttpModule,
        BrowserAnimationsModule,
        SharedModule.forRoot(),
        MaintenanceModule
]
...

Preloaded Routing Module 预载路由模块

import { NgModule } from '@angular/core';

... component imports

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

const resultsRoutes: Routes = [
    {
        path: '', component: ResultsComponent, children: [
            { path: 'featurechild', component: featureChildComponent }
        ]
    },
];

@NgModule({
    imports: [
        RouterModule.forChild(resultsRoutes)
    ],
    exports: [RouterModule]
})
export class ResultsRoutingModule {}

Preloaded Module 预装模块

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';

... other component imports

import { ResultsRoutingModule } from './results-routing.module';

...
imports: [
    CommonModule,
    ResultsRoutingModule,
    FormsModule,
    SharedModule,
...
export class ResultsModule {}

package.json 的package.json

{
  "name": "gui",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve --deploy-url=/huskies",
    "build": "ng build --dev --deploy-url=/huskies",
    "prod": "ng build --prod --deploy-url=/huskies",
    "test": "ng test",
    "lint": "ng lint",
    "pree2e": "webdriver-manager update --standalone false --gecko false --ignore_ssl",
    "e2e": "ng e2e -uw fal"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^7.0.2",
    "@angular/common": "^7.0.3",
    "@angular/compiler": "^7.0.3",
    "@angular/core": "^7.0.3",
    "@angular/forms": "^7.0.3",
    "@angular/http": "^7.0.3",
    "@angular/platform-browser": "^7.0.3",
    "@angular/platform-browser-dynamic": "^7.0.3",
    "@angular/platform-server": "^7.0.3",
    "@angular/router": "^7.0.3",
    "cesium": "^1.43.0",
    "core-js": "^2.5.7",
    "enhanced-resolve": "^3.4.1",
    "ng-event-source": "^1.0.14",
    "rxjs": "^6.3.3",
    "three": "^0.87.1",
    "zone.js": "^0.8.26"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.10.5",
    "@angular/cli": "^7.0.4",
    "@angular/compiler-cli": "^7.0.2",
    "@angular/language-service": "^7.0.2",
    "@types/jasmine": "^2.8.9",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^10.12.2",
    "codelyzer": "^4.5.0",
    "jasmine-core": "^3.3.0",
    "jasmine-spec-reporter": "^4.2.1",
    "karma": "^3.1.1",
    "karma-chrome-launcher": "^2.2.0",
    "karma-cli": "^1.0.1",
    "karma-coverage-istanbul-reporter": "^1.3.0",
    "karma-jasmine": "^1.1.2",
    "karma-jasmine-html-reporter": "^1.4.0",
    "protractor": "^5.4.1",
    "rxjs-tslint": "^0.1.5",
    "ts-node": "~3.3.0",
    "tslint": "^5.11.0",
    "typescript": "^3.1.6"
  }
}

folder structure (everything is in the root app directory): 文件夹结构(所有内容都在根应用目录中):

results/results.module.ts
results/results-routing.module.ts
app.module.ts
app-routing.module.ts

Sometime ng doesn't detect some reason. 有时ng无法检测到某些原因。

Can you run the command again 您可以再次运行命令吗

ng serve

If you are running through npm command then 如果通过npm命令运行,则

npm start

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM