简体   繁体   English

使用Webpack编译时出现TypeScript错误

[英]TypeScript error on compilation with webpack

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. 我在打字稿编译时遇到错误,我不知道它来自哪里-我尝试了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'.

Here is my tsconfig.json 这是我的tsconfig.json

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

} }

You installed typings for webpack-env and node -- those two modules both have ambient declarations for require and module . 您已经安装了webpack-env和node的类型-这两个模块都具有requiremodule的环境声明。 Tsc is complaining that require/module can't be re-declared with different types (lines 176 and 225 of webpack-env/index.d.ts). Tsc抱怨不能用不同的类型(webpack-env / index.d.ts的第176和225行)重新声明require / module。 Are you really using webpack-env typings? 您是否真的在使用webpack-env类型? Try removing webpack-env/index.d.ts and see. 尝试删除webpack-env / index.d.ts并查看。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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