Skip to content

How to use path aliases within a packages directory? #4304

Closed Answered by anthonyshew
himantyu-yuma asked this question in Help
Discussion options

You must be logged in to vote

This is a perfectly fine practice! But it does have another layer of configuration to make work. 😄

  • Subpath imports tell Node.js compilers where to look.
  • paths in tsconfig 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:

  "imports": {
    "#*": "./src/*"
  },

And in packages/ui/tsconfig.json:

  "compilerOptions": {
    "paths": {
      "#/*": ["./src/*"]
    }
  },

Now, everyone speaks the same importing language and you can build successfully. 🥳

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@singh-jay
Comment options

@anthonyshew
Comment options

Answer selected by anthonyshew
Comment options

You must be logged in to vote
1 reply
@ozhanefemeral
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
5 participants