TypeScript 尝试使用 Yarn Workspaces 编译同级文件夹的 node_modules
TypeScript tries to compile node_modules of sibling folder with Yarn Workspaces
我正在尝试使用 TypeScript 和 Yarn Workspaces 创建一个带有 "server" 和 "client" 文件夹的 monorepo 项目。在没有创建 "client" 文件夹的情况下编译 "server" 文件夹但效果很好,但是当我创建 "client" 文件夹时,编译 "server" 文件夹使得 TypeScript 想要编译 [= "client" 的 45=] 文件夹,给出错误但仍然编译。
错误如下:
../../../../.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.
我试过:
- 不使用工作区,
- 将 "client" 指定为 "server"、
的依赖项
- 从 "server" tsconfig 中排除 node_modules,
但没有结果。
我创建了一个测试仓库来重现错误(1- 克隆仓库,2- 纱线安装,3- cd 服务器,4- tsc):https://github.com/lewislbr/typescript-test
我错过了什么?
提前致谢。
通过以下方式解决:
- 正在将“@types/node”安装为常见的开发依赖项,
- 添加 "types": ["node"] 在公共 tsconfig.
我正在尝试使用 TypeScript 和 Yarn Workspaces 创建一个带有 "server" 和 "client" 文件夹的 monorepo 项目。在没有创建 "client" 文件夹的情况下编译 "server" 文件夹但效果很好,但是当我创建 "client" 文件夹时,编译 "server" 文件夹使得 TypeScript 想要编译 [= "client" 的 45=] 文件夹,给出错误但仍然编译。
错误如下:
../../../../.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.
我试过:
- 不使用工作区,
- 将 "client" 指定为 "server"、 的依赖项
- 从 "server" tsconfig 中排除 node_modules,
但没有结果。
我创建了一个测试仓库来重现错误(1- 克隆仓库,2- 纱线安装,3- cd 服务器,4- tsc):https://github.com/lewislbr/typescript-test
我错过了什么?
提前致谢。
通过以下方式解决:
- 正在将“@types/node”安装为常见的开发依赖项,
- 添加 "types": ["node"] 在公共 tsconfig.