I am working on my monorepo, and I'm getting this error trying to compile one of my modules
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.
Before I blindly follow these instructions, I'd like to know what causes this, since the config is exactly the same as my other modules.
I located the code that returns this error in the Typescript repository.
Based on that, I was able to solve my issue.
The layout of my module was such:
repo-root
- module
- - src
- - - code.ts
- - test
- - - code.test.ts
The name of the module was "my-module", and "code.test.ts" was trying to import the code via "my-module". Due to this, tsc
was calculating two possible project roots; "src" and "test".
The solution was to change the import in "test/code.test.ts" from "my-module" to "../src/code.ts" That caused tsc
to only see "src" as the project root, and resolved the error.