{"id":21710,"library":"prettier-plugin-shorten-imports","title":"prettier-plugin-shorten-imports","description":"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.","status":"active","version":"0.0.3","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/porky-prince/web-build-tools","tags":["javascript","prettier","prettier-plugin","shorten","imports","paths","typescript"],"install":[{"cmd":"npm install prettier-plugin-shorten-imports","lang":"bash","label":"npm"},{"cmd":"yarn add prettier-plugin-shorten-imports","lang":"bash","label":"yarn"},{"cmd":"pnpm add prettier-plugin-shorten-imports","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency – plugin requires Prettier >=2.0 to run","package":"prettier","optional":false},{"reason":"Peer dependency – needed for parsing tsconfig paths; can be >=2.9","package":"typescript","optional":true},{"reason":"Peer dependency – required for .vue file support; version ^2.1.0 || 3","package":"vue-tsc","optional":true}],"imports":[{"note":"Default import as a function; require works in CJS but ESM is preferred.","wrong":"const plugin = require('prettier-plugin-shorten-imports')","symbol":"default","correct":"import plugin from 'prettier-plugin-shorten-imports'"},{"note":"In Prettier config, use the package name string; require.resolve works but is unnecessary.","wrong":"plugins: [require.resolve('prettier-plugin-shorten-imports')]","symbol":"default (Prettier config usage)","correct":"plugins: ['prettier-plugin-shorten-imports']"},{"note":"Use the package name, not the path; Prettier resolves it from node_modules.","wrong":"prettier --plugin='./node_modules/prettier-plugin-shorten-imports' --write 'src/**/*.ts'","symbol":"default (CLI usage)","correct":"prettier --plugin=prettier-plugin-shorten-imports --write 'src/**/*.ts'"}],"quickstart":{"code":"npm install --save-dev prettier prettier-plugin-shorten-imports typescript\necho '{\n  \"compilerOptions\": {\n    \"baseUrl\": \".\",\n    \"paths\": {\n      \"@app/*\": [\"src/*\"]\n    }\n  }\n}' > tsconfig.json\nmkdir -p src/utils\necho 'export const formatName = (name: string) => name.toUpperCase();' > src/utils/format.ts\necho \"import { formatName } from '../../utils/format';\" > src/index.ts\nnpx prettier --plugin=prettier-plugin-shorten-imports --write src/index.ts\ncat src/index.ts","lang":"typescript","description":"Set up a tsconfig alias, create a file with a long relative import, and run Prettier to shorten it."},"warnings":[{"fix":"Manually update dynamic specifiers if needed; plugin only handles static import/export statements.","message":"Plugin does not rewrite dynamic imports (import()) or require() calls.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure specifiers point inside the project; external specifiers are left unchanged.","message":"Plugin does not modify specifiers that resolve outside the project root or to node_modules.","severity":"gotcha","affected_versions":"all"},{"fix":"If you need to rewrite external script src attributes, handle them separately.","message":"For .vue files, only <script> and <script setup> blocks are processed; <script src='...'> external scripts are ignored.","severity":"gotcha","affected_versions":"all"},{"fix":"Ensure the closest tsconfig to the file has the desired paths configuration.","message":"When multiple tsconfig.ts files exist (via extends), the nearest config's baseUrl and paths take precedence.","severity":"gotcha","affected_versions":"all"},{"fix":"Consider using an alternative plugin like prettier-plugin-organize-imports or prettier-plugin-import-sort if issues arise.","message":"Version 0.0.3 has not been updated since 2023; may not support Prettier 3+ features or newer TypeScript paths patterns.","severity":"deprecated","affected_versions":"0.0.3"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install typescript: npm install --save-dev typescript","cause":"Missing TypeScript peer dependency; plugin requires typescript to parse tsconfig.json.","error":"Error: Cannot find module 'typescript'"},{"fix":"Upgrade Prettier: npm install --save-dev prettier@latest","cause":"Running an older Prettier version that does not meet peer dependency requirement.","error":"Error: The plugin 'prettier-plugin-shorten-imports' requires a Prettier version >= 2.0"},{"fix":"Ensure a tsconfig.json or jsconfig.json exists in the project root or above the target file.","cause":"Plugin cannot locate a tsconfig.json or jsconfig.json in the file's directory tree.","error":"Error: No tsconfig or jsconfig found for file"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}