使用webpack进行编译时出现TypeScript错误

时间:2016-08-02 17:58:30

标签: javascript typescript webpack typescript1.8

我收到了一个有关打字稿编译的错误,我不知道它来自哪里 - 我尝试了很多不同的tsconfig.json设置组合,但我总是从webpack-env得到同样的两个错误。

(gec) ➜  optim ./node_modules/.bin/webpack --config webpack.config.js
ts-loader: Using typescript@1.8.10 and /home/bischoff_s/Code/optim/tsconfig.json
Hash: 0e608742cc4dff532c9a
Version: webpack 1.13.1
Time: 3182ms
                            Asset      Size      Chunks             Chunk Names
     main-0e608742cc4dff532c9a.ts   5.09 MB  0, 1, 2, 3  [emitted]  main
polyfills-0e608742cc4dff532c9a.ts  25 bytes     1, 2, 3  [emitted]  polyfills
      app-0e608742cc4dff532c9a.ts  25 bytes     2, 1, 3  [emitted]  app
   vendor-0e608742cc4dff532c9a.ts   3.63 kB     3, 1, 2  [emitted]  vendor
    + 329 hidden modules

ERROR in /home/guy/Code/optim/typings/globals/webpack-env/index.d.ts
(176,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'require' must be of type 'NodeRequire', but here has type 'RequireFunction'.

ERROR in /home/guyCode/optim/typings/globals/webpack-env/index.d.ts
(225,13): error TS2403: Subsequent variable declarations must have the same type.  Variable 'module' must be of type 'NodeModule', but here has type 'Module'.

这是我的tsconfig.json

{
    "compilerOptions": {
        "target": "es5",
        "module": "commonjs",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "sourceMap": true,
        "noEmitHelpers": true
    }

}

1 个答案:

答案 0 :(得分:1)

您安装了webpack-env和node的输入 - 这两个模块都具有 require 模块的环境声明。 Tsc抱怨不能使用不同类型(webpack-env / index.d.ts的第176和225行)重新声明require / module。你真的使用webpack-env打字吗?尝试删除webpack-env / index.d.ts并查看。