Prettier Plugin Sort Re-exports

raw JSON →
0.1.0 verified Sat Apr 25 auth: no javascript

Prettier plugin (v0.1.0) that sorts re-export statements by source path, ideal for barrel files. It groups re-exports separated by blank lines or comments and sorts each group independently. Requires Node >=18 and Prettier ^3. Unlike general export sorting plugins, this focuses only on re-exports and preserves group structure. Currently young with potential breaking changes in future versions.

error Cannot find module 'prettier-plugin-sort-re-exports'
cause Plugin not installed or not in node_modules.
fix
npm install --save-dev prettier-plugin-sort-re-exports
error Error: Cannot read properties of undefined (reading 'source')
cause Plugin encounters a non-re-export statement (e.g., export const).
fix
Only include re-export statements (export {…} from '…') in the file.
gotcha Plugin only sorts re-exports (export … from …), not regular export statements or other code.
fix Ensure your file contains only re-exports if you expect full sorting.
breaking Plugin may reorder groups if blank lines or comments are missing – groups are defined by separating blank lines.
fix Always separate logically distinct re-export groups with a blank line to prevent merging.
npm install prettier-plugin-sort-re-exports
yarn add prettier-plugin-sort-re-exports
pnpm add prettier-plugin-sort-re-exports

Install plugin, configure in .prettierrc, and run Prettier to sort re-exports by source path.

// No import needed – add to .prettierrc
// Install: npm install --save-dev prettier-plugin-sort-re-exports
// .prettierrc
{
  "plugins": ["prettier-plugin-sort-re-exports"]
}

// Then run prettier --write on your files
// Example barrel file (index.js):
export { b } from "./a/bar";
export { c } from "./a/baz";
export { a } from "./a/foo";