[英]Angular 4 AOT with webpack
我使用角度4與webpack 2並嘗試使用AOT,但它給我這個錯誤: 10% building modules 4/5 modules 1 active ..._modules/intl/locale-data/jsonp/en.jsModuleNotFoundError: Module not found: Error: Can't resolve './../$$_gendir/src/app/app.module.ngfactory' in '/Users/xyz/angular-upgrade/backend/myapp/angular/src'
。
這是我的webpack.config
:
new AotPlugin({
tsConfigPath: './tsconfig.json',
entryModule: './src/app/app.module#AppModule'
}),
我用來構建的腳本是: "build": "rimraf dist && webpack --config config/webpack.prod.js --progress --profile --bail"
下面是我的tsconfig.json
:
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"moduleResolution": "node",
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es2015", "dom"],
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true
},
"exclude": [
"node_modules",
"bower_components"
]
}
AOT現在不支持高於2.0.10的打字稿版本。 你需要確保這一點。 此外,你必須將一些角度模塊,如http,平台瀏覽器或核心更改回角度2 - 我使用版本2.4.0 - ,因為版本2.0.10或更低版本的打字稿不支持它們!
首先:你需要使用@ ngtools / webpack進行編譯。 然后你的編譯器選項不像Angular所希望的那樣。
請確保根據官方Angular AOT Cookbook配置您的設置和tsconfig.json
例如,module屬性需要設置為:
"module": "es2015"
此外,您應該通過指定告訴ngc將生成的源放在何處
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit": true
}
我和$$_gendir
有類似的錯誤
每個帖子從構建命令cli中刪除--bail
使我能夠看到更多的錯誤消息,因為$$_gendir
錯誤更多是由構建中的先前錯誤導致的一般消息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.