-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
What is the improvement or update you wish to see?
A more elaborate example of using subpath imports.
Wrote my experience below. If it is not a skill issue, I think it would be worth adding!
Thanks and have a nice day/evening,
Boris
Is there any context that might help us understand?
Starting from the current raw pnpm dlx create-turbo@latest install and following the Crafting your repository part of the doc, at one point subpath imports are mentioned.
Currently, it points to the Node.js doc and to the Use Node.js subpath imports instead of TypeScript compiler paths section of the doc.
But by just adding the recommended imports to the packages/ui/package.json, we can't use subpath imports yet.
{
"imports": {
"#*": "./src/*"
}
}Indeed, by importing Card from button we get an error: Cannot find module '#card' or its corresponding type declarations.
import { Card } from "#card";To fix it, we need to add .js, not ideal.
import { Card } from "#card.js";But then when running pnpm check-types we get into another problem: error TS2210: The project root is ambiguous, but is required to resolve import map entry 'card.js' in file '/Users/boris/Documents/Clients/Scienta/my-turborepo/packages/ui/package.json'. Supply the rootDir compiler option to disambiguate.
So we add rootDir in packages/ui/package.json
"compilerOptions": {
...
"rootDir": "src"
},And if we want to get rid of the .js from above, we have to do:
"imports": {
"#*": "./src/*.js"
},