jiti icon indicating copy to clipboard operation
jiti copied to clipboard

How to configure alias in jiti? Is there any detailed documentation?

Open szmxx opened this issue 2 years ago • 1 comments

Describe the feature

I want to use @ instead of ./src, for example @/utils is equivalent to ./src/utils

Additional information

  • [ ] Would you be willing to help implement this feature?

szmxx avatar Sep 15 '23 10:09 szmxx

yes, this should be supported.

i cannot use path aliases used in tsconfig.json in dependencies that use jiti like knip here -> https://github.com/webpro/knip/issues/515

i think the reason t3-env failed for me is probably also jiti. see -> https://github.com/t3-oss/t3-env/issues/180

would love support for this because i use path aliases in every project. i guess everyone does too as its much cleaner.

deadcoder0904 avatar Feb 20 '24 12:02 deadcoder0904

It is possible using alias config or (JITI_ALIAS).

tsconfig and other external configs are not infered (sorry i know it might feel a downside DX) but it is important to make jiti behavior portable and predictable.

Additionally since we use ESM resolution, node.js imports in package.json will be also respected for another way of setting aliases.

pi0 avatar Sep 25 '24 14:09 pi0

tsconfig and other external configs are not infered (sorry i know it might feel a downside DX) but it is important to make jiti behavior portable and predictable.

Hi pi0, I totally understand this reasoning, but I am realising that maintaining imports in package.json in addition to tsconfig may be difficult...

I've also hit this use-case where the TW module may use buildDir (aliased with #build) in config > c12 > jiti, same for @nuxt/eslint that could use #build instead (and ESLint is using jiti v2, although c12 would be amazing).

I see another request was raised here: https://github.com/unjs/jiti/issues/174#issuecomment-1823897652

Someone in Tailwind CSS discussions was proposing this: https://github.com/tailwindlabs/tailwindcss/discussions/12873#discussion-6173245

Do you think that the above solution should exist downstream and completely out of scope for jiti?

ineshbose avatar Mar 26 '25 12:03 ineshbose

Hi @pi0, I'm using jiti@v2 in my project and ran into the same issue. I'd really like to configure jiti to support tsconfig.paths. Unfortunately, I haven’t found any existing solution to achieve this.

The main problem is that jiti currently supports aliases as Record<string, string>, whereas tsconfig defines them as Record<string, string[]>.

I wanted to ask if you'd consider improving jiti to support working with tsconfig.paths. Here are a few possible ideas:

  1. Introduce a tsconfigPaths flag, which defaults to false. I saw your comment here where you mentioned you want to avoid relying on external config files to keep jiti predictable. That totally makes sense. But maybe if it’s a disabled-by-default flag, we can preserve that predictability while still giving devs the option to enhance their DX if needed?

  2. Extend the alias config to support Record<string, string | string[]>. This would allow devs to use external libraries like tsconfig-paths to read the aliases and pass them to jiti.

Thanks in advance! I hope it will be possible to introduce some improvements to jiti to support working with tsconfig.paths. At the moment, the DX really suffers without this feature.

alSergey avatar Apr 08 '25 06:04 alSergey

An opt-in feature to support ts aliases is acceptable. Do you mind to open a new issue to track?

pi0 avatar Apr 08 '25 06:04 pi0

Hi, I started a separate issue.

alSergey avatar Apr 08 '25 07:04 alSergey