简体   繁体   English

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

[英]Angular4 webpack gives error when production env but works on dev env

I am developing an app with Angular4 and .Net Core Mvc. 我正在使用Angular4和.Net Core Mvc开发应用程序。

When I run dev bundle script in package.json it works. 当我在package.json中运行开发包脚本时,它可以工作。 Script is below: 脚本如下:

del-cli wwwroot/dist/js/app && webpack --config webpack.config.dev.js --progress --profile --watch

When I run prod bundle script in package.json it gives error below: 当我在package.json中运行prod bundle脚本时,出现以下错误:

app.module.ngfactory.ts ... 'Promise' only refers to a type but is being used as a value here app.module.ngfactory.ts ...'Promise'仅指类型,但在此处用作值

Prod script is below: 产品脚本如下:

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'

My tsconfig.aot.json file is below: 我的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
  }

I cannot handle the error, I tried lots of things. 我无法处理错误,我尝试了很多事情。 I tried to add es2016, es2017 into lib part in tsconfig but didnot work. 我试图将es2016,es2017添加到tsconfig的lib部分中,但没有工作。

Also @types/core-js version in package.json is 0.9.39. 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"

Can you help me? 你能帮助我吗?

Thanks in advance 提前致谢

I wanted to bundle aot but normal tsconfig file affects aot bundle. 我想捆绑aot,但是普通的tsconfig文件会影响aot捆绑。 So I prepared normal tsconfig file like below, problem solved: 所以我准备了普通的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