繁体   English   中英

Angular4 Webpack在生产环境时出现错误,但在开发环境中有效

[英]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.

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