Registry / devops / prettier-plugin-shorten-imports

prettier-plugin-shorten-imports

JSON →
library0.0.3jsnpmunverified

Prettier plugin that rewrites local import and export specifiers to the shortest path depth based on tsconfig.json or jsconfig.json paths mappings. Version 0.0.3, released early 2023, with no further updates since. Supports .js, .jsx, .ts, .tsx, and .vue files, preserving file extensions and normalizing to POSIX separators. It compares relative paths and path aliases, keeping the shortest depth, and skips specifiers resolving to node_modules or outside the project root. Differentiators: integrates with Prettier formatting, avoids long relative paths, respects existing TypeScript/JavaScript path aliases, and merges paths from extended tsconfig chains.

npm install prettier-plugin-shorten-imports
INSTALL
IMPORT
SIG · PRETTIER-PLUGIN-SH
P
prettier-plugin-shorten-imports
devopsjavascriptv0.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import plugin from 'prettier-plugin-shorten-imports'
const plugin = require('prettier-plugin-shorten-imports')
Default import as a function; require works in CJS but ESM is preferred.
default (Prettier config usage)
plugins: ['prettier-plugin-shorten-imports']
plugins: [require.resolve('prettier-plugin-shorten-imports')]
In Prettier config, use the package name string; require.resolve works but is unnecessary.
default (CLI usage)
prettier --plugin=prettier-plugin-shorten-imports --write 'src/**/*.ts'
prettier --plugin='./node_modules/prettier-plugin-shorten-imports' --write 'src/**/*.ts'
Use the package name, not the path; Prettier resolves it from node_modules.

Set up a tsconfig alias, create a file with a long relative import, and run Prettier to shorten it.

npm install --save-dev prettier prettier-plugin-shorten-imports typescript echo '{ "compilerOptions": { "baseUrl": ".", "paths": { "@app/*": ["src/*"] } } }' > tsconfig.json mkdir -p src/utils echo 'export const formatName = (name: string) => name.toUpperCase();' > src/utils/format.ts echo "import { formatName } from '../../utils/format';" > src/index.ts npx prettier --plugin=prettier-plugin-shorten-imports --write src/index.ts cat src/index.ts
Debug
Known issues
gotchaPlugin does not rewrite dynamic imports (import()) or require() calls.
fix
Manually update dynamic specifiers if needed; plugin only handles static import/export statements.
affects: all
gotchaPlugin does not modify specifiers that resolve outside the project root or to node_modules.
fix
Ensure specifiers point inside the project; external specifiers are left unchanged.
affects: all
gotchaFor .vue files, only <script> and <script setup> blocks are processed; <script src='...'> external scripts are ignored.
fix
If you need to rewrite external script src attributes, handle them separately.
affects: all
gotchaWhen multiple tsconfig.ts files exist (via extends), the nearest config's baseUrl and paths take precedence.
fix
Ensure the closest tsconfig to the file has the desired paths configuration.
affects: all
deprecatedVersion 0.0.3 has not been updated since 2023; may not support Prettier 3+ features or newer TypeScript paths patterns.
fix
Consider using an alternative plugin like prettier-plugin-organize-imports or prettier-plugin-import-sort if issues arise.
affects: 0.0.3
Errors
Common errors & fixes
Error: Cannot find module 'typescript'
Missing TypeScript peer dependency; plugin requires typescript to parse tsconfig.json.
fix
Install typescript: npm install --save-dev typescript
Error: The plugin 'prettier-plugin-shorten-imports' requires a Prettier version >= 2.0
Running an older Prettier version that does not meet peer dependency requirement.
fix
Upgrade Prettier: npm install --save-dev prettier@latest
Error: No tsconfig or jsconfig found for file
Plugin cannot locate a tsconfig.json or jsconfig.json in the file's directory tree.
fix
Ensure a tsconfig.json or jsconfig.json exists in the project root or above the target file.
Upgrade
Version history
0.0.3latest on npm
Audit
Dependencies
prettierrequiredPeer dependency – plugin requires Prettier >=2.0 to run
typescriptoptionalPeer dependency – needed for parsing tsconfig paths; can be >=2.9
vue-tscoptionalPeer dependency – required for .vue file support; version ^2.1.0 || 3
Agent activity
2 hits · last 30 days
node
2
Resources
prettier-plugin-shorten-imports — npm install prettier-plugin-shorten-imports · libregistry