2
votes

I'm trying to make a monorepo project with "server" and "client" folders using TypeScript and Yarn Workspaces. Compiling the "server" folder without having created the "client" folder yet works well, but when I create the "client" folder, compiling the "server" folder makes TypeScript wanting to compile the node_modules folder of "client", giving errors but compiling nonetheless.

The errors are like:

../../../../.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.

I've tried:

  • not using Workspaces,
  • specifying "client" as a dependency of "server",
  • excluding node_modules from "server" tsconfig,

but no results.

I've created a test repo to reproduce the errors (1- clone repo, 2- yarn install, 3- cd server, 4- tsc): https://github.com/lewislbr/typescript-test

What am I missing?

Thanks in advance.

1

1 Answers

5
votes

Solved it by:

  • Installing "@types/node" as a common dev dependency,
  • Adding "types": ["node"] in the common tsconfig.

🎉