How to use path aliases within a packages directory? #4304
-
I am currently developing an application using turborepo and Remix, and I would like to use path aliases within the packages directory.
I want to import I tried setting up the {
"compilerOptions": {
"baseUrl": "./",
"paths": {
"@/*": ["./*"],
},
}
} But I got errors and the path didn't resolve. I read this Discussion( #620 ), but I want to use If anyone knows how to set up path aliases in a monorepo setup using turborepo for importing packages. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
This is a perfectly fine practice! But it does have another layer of configuration to make work. 😄
What you end up with is a mismatch between what your compiler sees and what you see in your editor. So, to use subpath imports, you'll need to follow the rules of Node.js (since they're more strict than TypeScript here. In
And in
Now, everyone speaks the same importing language and you can build successfully. 🥳 |
Beta Was this translation helpful? Give feedback.
-
I fixed it, my typescript version 5.4.5 here's what i change packages/ui/package.json "imports": {
"#dep/*": [
"./src/*.ts",
"./src/*.tsx"
]
}, and for packages/ui/tsconfig.json {
"extends": "@repo/typescript-config/react-library.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "."
},
"exclude": ["node_modules", "dist"]
} and this is how i import the component import { cn } from '#dep/lib/utils'; |
Beta Was this translation helpful? Give feedback.
This is a perfectly fine practice! But it does have another layer of configuration to make work. 😄
paths
intsconfig
tell TypeScript where to look.What you end up with is a mismatch between what your compiler sees and what you see in your editor.
So, to use subpath imports, you'll need to follow the rules of Node.js (since they're more strict than TypeScript here.
In
packages/ui/package.json
:And in
packages/ui/tsconfig.json
:Now, everyone speaks the same importing language and you can build successfully. 🥳