javascript - 使用 webpack 编译时出现 TypeScript 错误

标签 javascript typescript webpack typescript1.8

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

}

最佳答案

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

关于javascript - 使用 webpack 编译时出现 TypeScript 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38727442/

相关文章:

javascript - 尝试将图标链接到显示我的电子邮件和功能的窗口,以便人们可以通过我的网站与我联系

javascript - 获取特定单元中某个css属性的值

javascript - 如何为以字符串为键、以 React SFC 作为值的对象包装器定义 TypeScript 类型?

sass - 如何将 `css-modules` 与普通 `sass` 结合起来,最好在 `webpack` 中

reactjs - 如何在 Create React App 中不显示警告

javascript - 类型 'toPromise' 上不存在属性 'Observable<Response>' 并且参数 'response' 隐式具有 'any' 类型

javascript - 选择/拖动文本时停止页面滚动

javascript - 运行 npm run pactTest 时 PACT.io : Getting Missing requests error,

typescript - 为什么在这种情况下接口(interface)不保护我?

vue.js - 使用 Vue 2 设置 Webpack 5 时出现 "Cannot find module ' vue/compiler-sfc'"