使用Webpack编译时出现TypeScript错误 [英] TypeScript error on compilation with webpack

查看:722
本文介绍了使用Webpack编译时出现TypeScript错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在打字稿编译时遇到错误,也不知道它的来源-我尝试了tsconfig.json设置的许多不同组合,但是我总是从webpack-env中得到相同的两个错误.

I am getting an error with typescript compilation and I have no clue where its coming from - I have tried many different combinations of tsconfig.json setups but I always get the same two errors from 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

Here is my tsconfig.json

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

}

推荐答案

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

You installed typings for webpack-env and node -- those two modules both have ambient declarations for require and module. Tsc is complaining that require/module can't be re-declared with different types (lines 176 and 225 of webpack-env/index.d.ts). Are you really using webpack-env typings? Try removing webpack-env/index.d.ts and see.

这篇关于使用Webpack编译时出现TypeScript错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆