Menu

Subpath Imports With #/: The Path Alias Node Actually Understands
📰

Subpath Imports With #/: The Path Alias Node Actually Understands

DEV Community: node·Danny Holloran·4 days ago
#M3bVKRpE
#devtonodejs#devto#dev#src#lib
Reading 0:00
15s threshold

Count the places your @/ import alias is defined. There's paths in tsconfig.json so the editor stops complaining. There's resolve.alias in vite.config.ts so the dev server can find the file. If you run tests, there's probably vite-tsconfig-paths or a Jest moduleNameMapper doing the same job a third time. And if any of that code ever runs directly in Node, none of those configs help, because Node has never read a tsconfig in its life.

That arrangement got less comfortable this year. TypeScript 6.0 deprecated baseUrl , and the TypeScript 7 native compiler drops it entirely. Meanwhile the platform quietly fixed the thing that kept people from using the standard alternative. Node's package.json imports field now accepts a bare #/ prefix, and TypeScript 6.0 understands it. You can have one alias, defined once, that every tool in the chain reads from the same place.

What actually changed

Subpath imports have existed in Node since v14.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.