TypeScript尝试使用Yarn Workspaces编译同级文件夹的node_modules

时间:2019-08-22 11:58:37

标签: typescript yarnpkg yarn-workspaces

我正在尝试使用TypeScript和Yarn Workspaces使用“ server”和“ client”文件夹创建一个monorepo项目。在没有创建“ client”文件夹的情况下编译“ server”文件夹仍然可以正常工作,但是当我创建“ client”文件夹时,编译“ server”文件夹会使TypeScript希望编译“ client”的node_modules文件夹,但会出错,但是仍然可以编译。

错误类似于:

  

../../../../。config / yarn / global / node_modules / typescript / lib / lib.dom.d.ts:5353:11-错误TS2300:标识符'FormData'重复。 / p>      

5353接口FormData {                  ~~~~~~~~

     

../ node_modules/@types/react-native/globals.d.ts:40:15       40声明类FormData {                        ~~~~~~~~~   此处也声明了“ FormData”。

     

../../../../。config / yarn / global / node_modules / typescript / lib / lib.dom.d.ts:5363:13-错误TS2300:标识符'FormData'重复。 / p>      

5363声明var FormData:{                    ~~~~~~~~

     

../ node_modules/@types/react-native/globals.d.ts:40:15       40声明类FormData {                        ~~~~~~~~~   此处也声明了“ FormData”。

     

../../../../。config / yarn / global / node_modules / typescript / lib / lib.dom.d.ts:15671:11-错误TS2300:标识符'URLSearchParams'重复。 / p>      

15671接口URLSearchParams {                   ~~~~~~~~~~~~~~~

     

../ node_modules/@types/react-native/globals.d.ts:258:15       258声明的类URLSearchParams {                         ~~~~~~~~~~~~~~~   这里也声明了“ URLSearchParams”。

我尝试过:

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

但没有结果。

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

我想念什么?

谢谢。

1 个答案:

答案 0 :(得分:0)

通过以下方式解决它:

  • 将“ @ types / node”安装为常见的dev依赖项,
  • 在通用tsconfig中添加“类型”:[“节点”]。

?