这是indexloc提供的服务,不要输入任何密码
Skip to content
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: 3 comments 10 replies

Comment options

You must be logged in to vote
4 replies
@anthonyshew
Comment options

@Hyperion147
Comment options

@issam-seghir
Comment options

@Nikola-Milovic
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
6 replies
@anthonyshew
Comment options

@iantanwx
Comment options

@braden-w
Comment options

@karatashsyn
Comment options

@Nikola-Milovic
Comment options

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