[英]Angular4 webpack gives error when production env but works on dev env
我正在使用Angular4和.Net Core Mvc開發應用程序。
當我在package.json中運行開發包腳本時,它可以工作。 腳本如下:
del-cli wwwroot/dist/js/app && webpack --config webpack.config.dev.js --progress --profile --watch
當我在package.json中運行prod bundle腳本時,出現以下錯誤:
app.module.ngfactory.ts ...'Promise'僅指類型,但在此處用作值
產品腳本如下:
del-cli wwwroot/dist/js/app && ngc -p tsconfig.aot.json && ngc -p tsconfig.aot.json && webpack --config webpack.config.prod.js --progress --profile --bail && del-cli 'wwwroot/dist/js/app/**/*.js' 'wwwroot/dist/js/app/**/*.js.map' '!wwwroot/dist/js/app/bundle.js' '!wwwroot/dist/js/app/*.chunk.js' 'ClientApp/app/**/*.ngfactory.ts' 'ClientApp/app/**/*.shim.ts' 'ClientApp/app/**/*.ngsummary.json' 'ClientApp/app/**/*.ngstyle.ts'
我的tsconfig.aot.json文件如下:
"compilerOptions": {
"module": "es2015",
"target": "es5",
"lib": [
"es2015",
"dom"
],
"moduleResolution": "node",
"noImplicitAny": false,
"sourceMap": false,
"removeComments": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"outDir": "./wwwroot/dist/js/app"
},
"types": [ "node", "lodash", "core-js" ],
"typeRoots": [
"node_modules/@types"
],
"angularCompilerOptions": {
"skipMetadataEmit": true
}
我無法處理錯誤,我嘗試了很多事情。 我試圖將es2016,es2017添加到tsconfig的lib部分中,但沒有工作。
package.json中的@ types / core-js版本也是0.9.39。
"@types/core-js": "^0.9.39",
"@types/lodash": "^4.14.59",
"@types/node": "^6.0.45",
"typescript": "^2.2.2"
你能幫助我嗎?
提前致謝
我想捆綁aot,但是普通的tsconfig文件會影響aot捆綁。 所以我准備了普通的tsconfig文件,如下所示,問題已解決:
{
"compileOnSave": false,
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"lib": [ "es2016", "dom" ],
"moduleResolution": "node",
"noImplicitAny": false,
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"skipLibCheck": true
},
"exclude": [
"node_modules",
"wwwroot/dist/js"
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.