gpt4 book ai didi

TypeScript 尝试使用 Yarn Workspaces 编译兄弟文件夹的 node_modules

转载 作者:行者123 更新时间:2023-12-04 16:42:25 25 4
gpt4 key购买 nike

我正在尝试使用 TypeScript 和 Yarn Workspaces 创建一个包含“服务器”和“客户端”文件夹的 monorepo 项目。在没有创建“client”文件夹的情况下编译“server”文件夹但效果很好,但是当我创建“client”文件夹时,编译“server”文件夹使得 TypeScript 想要编译“client”的 node_modules 文件夹,但出现错误尽管如此编译。

错误如下:

../../../../.config/yarn/global/node_modules/typescript/lib/lib.dom.d.ts:5353:11 - error TS2300: Duplicate identifier 'FormData'.

5353 interface FormData { ~~~~~~~~

../node_modules/@types/react-native/globals.d.ts:40:15 40 declare class FormData { ~~~~~~~~ 'FormData' was also declared here.

../../../../.config/yarn/global/node_modules/typescript/lib/lib.dom.d.ts:5363:13 - error TS2300: Duplicate identifier 'FormData'.

5363 declare var FormData: { ~~~~~~~~

../node_modules/@types/react-native/globals.d.ts:40:15 40 declare class FormData { ~~~~~~~~ 'FormData' was also declared here.

../../../../.config/yarn/global/node_modules/typescript/lib/lib.dom.d.ts:15671:11 - error TS2300: Duplicate identifier 'URLSearchParams'.

15671 interface URLSearchParams { ~~~~~~~~~~~~~~~

../node_modules/@types/react-native/globals.d.ts:258:15 258 declare class URLSearchParams { ~~~~~~~~~~~~~~~ 'URLSearchParams' was also declared here.

我试过:

  • 不使用工作区,
  • 将“客户端”指定为“服务器”的依赖项,
  • 从“服务器”tsconfig 中排除 node_modules,

但没有结果。

我创建了一个测试仓库来重现错误(1- 克隆仓库,2- yarn 安装,3- cd 服务器,4- tsc):https://github.com/lewislbr/typescript-test

我错过了什么?

提前致谢。

最佳答案

通过以下方式解决:

  • 将“@types/node”安装为常见的开发依赖项,
  • 在公共(public) tsconfig 中添加 "types": ["node"]。

🎉

关于TypeScript 尝试使用 Yarn Workspaces 编译兄弟文件夹的 node_modules,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57608871/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com