Path aliasing, sometimes referred to as import or module resolution, in the earliest and most naïve sense, is a method of overloading the Node Require Resolution Algorithm so that it first looks in some particular defined folders for modules of a given name before looking for installed modules of the same name in node_modules
folders. While this seems handy at first glance, in practice, it’s is an unnecessary maintenance overhead in large distributed teams and a sign of poor code organization and architecture. This topic is covered in depth in the article “Import path aliasing is a crutch for poor architecture”.
This project enables you to quickly and automatically remove import path aliasing from your codebase.
npx remove-aliasing [options] <directory>
npx remove-aliasing@latest --root="src/" --prefix="@/" src/
import { Foo } from '@/components/Foo';import * as Bar from '@/api/shared/services/bar';
import { Foo } from '../../components/Foo';import * as Bar from '../../api/shared/services/bar';
Option | Alias | Type | Description | Required |
---|---|---|---|---|
--root | -r | string | Directory that serves as the root of aliased files | ✅ |
--prefix | -p | string | Import path prefix, if any | |
--parser | string | Parser to use when reading files. Default tsx | ||
--dry-run | boolean | Do not actually write, just see what will happen | ||
--verbosity | -v | number | Show more information about the transform process. Default 0 | |
--version | Show the program version |