我一直在嘗試一段時間才能獲得一個懶惰的加載模塊在簡單的AOT + Webpack Angular 2建立。找不到模塊'./sections/lazy/lazy.module.ngfactory'錯誤在Angular 2 Webpack + AOT設置
以下是我的核心設置,如果有其他任何內容有助於創建更多上下文,請讓我知道,我會更新問題。
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"declaration": false,
"removeComments": true,
"noLib": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["dom", "es6"],
"sourceMap": true,
"pretty": true,
"allowUnreachableCode": false,
"allowUnusedLabels": false,
"noImplicitAny": true,
"noImplicitReturns": true,
"noImplicitUseStrict": false,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"outDir": "build/tmp",
"typeRoots": [
"./node_modules/@types"
],
"types": [
"node",
"jasmine"
]
},
"exclude": [
"build",
"dist",
"node_modules",
"src/main.aot.ts",
"tmp"
],
"angularCompilerOptions": {
"debug": true,
"genDir": "build",
"skipMetadataEmit": true
},
"compileOnSave": false,
"buildOnSave": false
}
app.routing.ts
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
export const routes: Routes = [
{ path: 'lazy', loadChildren: './sections/lazy/lazy.module#RecipesModule' },
];
@NgModule({
imports: [RouterModule.forRoot(routes)],
exports: [RouterModule],
})
export class AppRoutingModule { }
webpack.prod.js
// ...
module: {
rules: [
{
test: /\.ts$/,
loader: '@ngtools/webpack',
}
]
}
// ...
plugins: [
// ...
new AotPlugin({
tsConfigPath: './tsconfig.json',
entryModule: helpers.root('src/app/app.module#AppModule')
}),
// ...
]
// ...
的構建過程完成後沒有任何問題,但是當我嘗試導航到/lazy
網址時發生錯誤Error: Uncaught (in promise): Error: Cannot find module './sections/lazy/lazy.module.ngfactory'.
。
同時在開發/ JIT中運行應用程序沒有任何問題。
您是否發現任何問題?
感謝
同樣的問題與我們的樣本回購[這裏](https://github.com/BrainCrumbz/ngtools-webpack-demo)。還有一個[分支](https://github.com/BrainCrumbz/ngtools-webpack-demo/tree/feat/jit-entry-point),使用JiT入口點代替AoT入口點。兩種情況都沒有運氣。 – superjos
嗨@superjos我發佈了一個答案,可能會解決你的問題,因爲你在你的webpack配置中使用相同的插件,希望它可以幫助 – crash