我正在將我的 Angular 8 projet 升級到 Angular 12,也升級到 webpack 5。該專案在開發模式下構建并運行良好,但它沒有在 AOT 模式下構建。我的main-aot.ts檔案正在尋找app.module.ngfactory未生成的檔案。程序中沒有報告其他錯誤。我的問題:
- 用
AngularWebpackPluginnow 代替 可以AngularCompilerPlugin嗎? - 我的
main-aot.ts檔案(如下)是否正確?我使用與 Angular 8 相同的方法。 - 如果
ngfactory沒有生成檔案,有沒有辦法獲取錯誤資訊,指出問題的原因? - 我還應該做些什么來
ngfactory創建檔案?
筆記
- Angular 的確切版本是 12.2.11。webpack 版本是 5.59.1。
- 我在下面顯示的檔案內容中跳過了幾行。如果需要,我可以添加更多。
main-aot.ts
import { platformBrowser } from "@angular/platform-browser";
import { enableProdMode } from "@angular/core";
import { AppModuleNgFactory } from "./app/app.module.ngfactory";
enableProdMode();
platformBrowser().bootstrapModuleFactory(AppModuleNgFactory);
webpack-prod.js
module: {
rules: [
{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
loader: '@ngtools/webpack'
},
...
]
}
...
plugins: [
new AngularWebpackPlugin({
tsconfig: './tsconfig-aot.json',
}),
...
],
...
tsconfig-aot.json
{
"compilerOptions": {
...
},
"files": [
"clientApp/app/app.module.ts",
"clientApp/main-aot.ts",
"clientApp/polyfills.ts",
"clientApp/vendor.ts"
],
"angularCompilerOptions": {
"skipMetadataEmit": true,
"trace": true,
"enableIvy": true /* Setting false does not help */
},
...
}
構建輸出(相關內容)
92% sealing asset processing TerserPlugin(node:6128)
...
modules by path ./node_modules/ 3.31 MiB
...
modules by path ./clientApp/ 9.56 KiB
./clientApp/vendor.ts 1 modules 647 bytes [built] [code generated]
./clientApp/polyfills.ts 1 modules 8.64 KiB [built] [code generated]
./clientApp/main-aot.ts 296 bytes [built] [code generated]
92 ms (resolving: 28 ms, restoring: 0 ms, integration: 0 ms, building: 64 ms, storing: 0 ms)
...
ERROR in ./clientApp/main-aot.ts 4:0-64
Module not found: Error: Can't resolve './app/app.module.ngfactory' in 'D:\...\clientApp'
resolve './app/app.module.ngfactory' in 'D:\...\clientApp'
using description file: D:\...\package.json (relative path: ./clientApp)
using description file: D:\...\package.json (relative path: ./clientApp/app/app.module.ngfactory)
(several lines for: no extension, .ts, .js, .json, .css, .scss, .html, and as directory)
D:\...\clientApp\app\app.module.ngfactory doesn't exist
...
uj5u.com熱心網友回復:
我在GitHub 上從Alan Agius那里得到了答案:
這是預期的。Ivy 不再生成ngfactory檔案。您可以洗掉.ngfactory參考。
import { platformBrowser } from "@angular/platform-browser"; import { enableProdMode } from "@angular/core"; import { AppModule } from "./app/app.module"; enableProdMode(); platformBrowser().bootstrapModule(AppModule);
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/341225.html
標籤:有角的 网络包 angular2-aot
