A walkthrough of enforcing Node.js subpath imports as the sole import style in a codebase. It covers setting up subpath mappings in package.json for TypeScript and runtime resolution, using ESLint's no-restricted-imports rule to block relative and alias-style imports, and using the perfectionist/sort-imports rule to keep import groups consistently ordered. The author acknowledges the approach is opinionated and may not suit every team.

4m read timeFrom johnnyreilly.com
Post cover image
Table of contents
First a warning ​Node.js subpaths only ​Block alternatives with no-restricted-imports ​Keep import groups predictable with perfectionist/sort-imports ​Does this work with TypeScript? ​Is this actually a good idea? ​Conclusion ​

Sort: