我正在开发我的 monorepo,并且在尝试编译我的模块之一时遇到此错误
error TS2209: The project root is ambiguous,
but is required to resolve export map entry '.' in file '<module_path>/package.json'.
Supply the `rootDir` compiler option to disambiguate.
在我盲目遵循这些说明之前,我想知道是什么原因造成的,因为配置与我的其他模块完全相同。
我在 Typescript 存储库中找到了 返回此错误的代码。
基于此,我能够解决我的问题。
我的模块的布局是这样的:
repo-root
- module
- - src
- - - code.ts
- - test
- - - code.test.ts
模块的名称是“my-module”,“code.test.ts”试图通过“my-module”导入代码。因此,
tsc
正在计算两个可能的项目根; “src”和“测试”。
解决方案是将“test/code.test.ts”中的导入从“my-module”更改为“../src/code.ts”,这导致
tsc
仅将“src”视为项目根,并解决了错误。