【问题标题】:Running `tsc` on project using Webpack throws errors not seen in webpack使用 Webpack 在项目上运行 `tsc` 会引发 webpack 中看不到的错误
【发布时间】:2018-04-29 00:30:36
【问题描述】:

我使用 Webpack 来构建我的 Typescript 项目。但是,随着我的项目越来越大,webpack 的速度变慢了。

我想使用 tsc 将 typescript 签出拆分为一个单独的进程。

但是,当我在我的项目上运行 tsc 时,我收到了在将 ts-loader 用于 Webpack 时没有遇到的类型声明错误。

我认为这是由于 typescript 和 webpack 在导入模块方面的不同。

模块分辨率: 意识到这个插件使用打字稿是非常重要的, 不是 webpack 的模块解析。这意味着您必须设置 tsconfig.json 正确。例如,如果您设置文件: ['./src/someFile.ts'] in tsconfig.json,这个插件只会检查 someFile.ts 用于语义错误。这是因为性能。目标 这个插件是尽可能快的。使用打字稿的模块 我们不必等待 webpack 编译文件(其中 在编译期间遍历依赖图) - 我们有一个完整的列表 从一开始的文件。 https://github.com/Realytics/fork-ts-checker-webpack-plugin#modules-resolution

以下是一些错误示例:

node_modules/@types/node/index.d.ts:143:13 - error TS2300: Duplicate identifier 'require'.
node_modules/@types/react-native/index.d.ts:8719:14 - error TS2300: Duplicate identifier 'require'.
node_modules/@types/react-native/index.d.ts:8745:18 - error TS2717: Subsequent property declarations must have the same type.  Property 'geolocation' must be of type 'Geolocation', but here has type 'GeolocationStatic'.
node_modules/@types/webpack-env/index.d.ts:203:13 - error TS2300: Duplicate identifier 'require'.
node_modules/rxjs/scheduler/VirtualTimeScheduler.d.ts:24:15 - error TS2416: Property 'work' in type 'VirtualAction<T>' is not assignable to the same property in base type 'AsyncAction<T>'.

更多详情:https://gist.github.com/IanEdington/b1567b2cabae262eac8a6ef6a4206d4b

【问题讨论】:

    标签: typescript webpack


    【解决方案1】:

    感谢@qDot 解决这个问题:https://github.com/Realytics/fork-ts-checker-webpack-plugin/issues/116#issuecomment-385286544

    这是节点和打字稿库冲突的问题。见:

    https://github.com/Microsoft/TypeScript/issues/23769

    快速修复:返回到@types/node v9.6.7,直到可以修复 v10。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-28
      • 2020-02-18
      • 1970-01-01
      • 2020-02-01
      • 1970-01-01
      • 2018-05-05
      • 1970-01-01
      • 2018-09-04
      相关资源
      最近更新 更多