-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[feat]: CLI support for package.json subpath imports #2960
Comments
This issue has been automatically closed because it received no activity for a while. If you think it was closed by accident, please leave a comment. Thank you. |
Turborepo now officially recommends node subpath imports for internal packages in their docs:
Thanks @jeremy-code for the workaround, but would be amazing if shadcn supported this at some point, since I imagine this will become much more prevalent in the near future. |
I'm facing a similar issue, it would be cool that the CLI get fixed on the path alias. Currently, it seems like if the CLI detects that in the tsconfig there is a "wrong" alias (such as Node subpath can only begin with a The only way to fix it is whenever you add a new component with the CLI, you need to fix the path alias by hand (unless someone else finds another solution?) |
Reactivate this please! |
A workaround that involves not using aliases is using Node.js self-referencing. For instance, see the following code: // package.json
{
"name": "@repo/ui",
"exports": {
"./globals.css": "./globals.css",
"./postcss.config": "./postcss.config.js",
"./tailwind.config": "./tailwind.config.ts",
"./utils": "./utils.ts",
"./components/*": "./components/*.tsx",
"./components/ui/*": "./components/ui/*.tsx"
},
}
// components.json
{
"aliases": {
"utils": "@repo/ui/utils",
"components": "@repo/ui/components"
}
} Then, internally (in @repo/ui), imports will look like IMO, due to the package structure (few imports), this is more useful than using aliasing since it just bases everything based on what you export. The only issue is if you have some internal tool in the library that you don't want to export, but at least for EDIT: shadcn/ui has released experimental monorepo support using the internal packages (@workspace/ui) structure. |
After playing around with things for a while, I was able to get subpath imports working with shadcn/ui components nearly perfectly. My package is a Compiled Package, thus the
It is unfortunate to need the TS path alias in addition to the subpath import, but this gets you 99% there. The only thing that does not seem to work with this setup is the generated |
I ended up going the self-referencing route, here's what the exports (in package.json) ended up looking like: "exports": {
"./utils/*": {
"types": "./src/lib/utils/*.ts",
"default": "./src/lib/utils/*.ts"
},
"./lib/*": {
"types": "./src/lib/*.ts",
"default": "./src/lib/*.ts"
},
"./components/*": {
"types": "./src/components/*.tsx",
"default": "./src/components/*.tsx"
},
"./ui/*": {
"types": "./src/components/ui/*.tsx",
"default": "./src/components/ui/*.tsx"
},
"./hooks/*": {
"types": "./src/hooks/*.tsx",
"default": "./src/hooks/*.tsx"
}
} And in tsconfig.json: "paths": {
"@repo/ui/*": ["./src/*"]
} This helped me get rid of I think I ran into issues with |
This issue has been automatically marked as stale due to two years of inactivity. It will be closed in 7 days unless there’s further input. If you believe this issue is still relevant, please leave a comment or provide updated details. Thank you. |
Feature description
In TypeScript 5.4, subpath imports are now supported. In
components.json
, if the subpath import is added as an alias like:It will create a new folder called #components, and put all the components in there. Conversely, if the alias is set to the actual components directory (e.g. ./src/components/ui), an error will be thrown as an array of errors like:
Not setting any alias at all results in error "Invalid configuration found in ../components.json".
In the meantime, I have set it with the subpath imports as the alias, and added bash commands to move it to the correctly place, but this isn't ideal.
Affected component/components
No response
Additional Context
No response
Before submitting
The text was updated successfully, but these errors were encountered: