【问题标题】:Angular4 webpack gives error when production env but works on dev envAngular4 webpack在生产环境中出错但在开发环境中工作
【发布时间】:2017-05-18 13:34:03
【问题描述】:

我正在使用 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' 仅指一种类型,但在此处用作值

Prod 脚本如下:

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"

你能帮帮我吗?

提前致谢

【问题讨论】:

    标签: json angular asp.net-core-mvc


    【解决方案1】:

    我想捆绑 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"
      ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-05
      • 2019-04-14
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 2021-06-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多