问题
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'.
Here is my tsconfig.json
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"sourceMap": true,
"noEmitHelpers": true
}
}
回答1:
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.
来源:https://stackoverflow.com/questions/38727442/typescript-error-on-compilation-with-webpack