prettier-plugin-tsconfig

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

A Prettier plugin that formats tsconfig.json files by sorting keys according to the official TypeScript tsconfig reference order. Version 0.0.1 is an early release with basic functionality, no comment support, and is marked as work-in-progress. It requires Prettier ^2.0.0 as a peer dependency and Node >=12. Differs from general JSON formatters by applying a specific key ordering for TypeScript configuration files, making tsconfig.json more predictable and easier to navigate.

error Error: Cannot find module 'prettier-plugin-tsconfig'
cause Plugin not installed or not in node_modules
fix
Run 'npm install --save-dev prettier-plugin-tsconfig' to install the plugin.
error Error: [prettier-plugin-tsconfig] Comments are not supported
cause tsconfig.json contains // or /* */ comments
fix
Remove comments from tsconfig.json before running prettier.
error Unexpected token } in JSON at position X
cause Invalid JSON due to trailing comma or syntax error
fix
Ensure tsconfig.json is valid JSON; remove trailing commas and malformed syntax.
gotcha This plugin does NOT support comments in tsconfig.json. Comments will be removed during formatting.
fix Remove comments from tsconfig.json before formatting, or use a different tool.
gotcha Plugin is a work-in-progress. Always check the formatted tsconfig.json before committing.
fix Review diff before committing; manually verify key ordering is as expected.
gotcha Only formats files named 'tsconfig.json'. Other JSON files with TypeScript config extensions (e.g., tsconfig.app.json) are not formatted unless glob is explicitly changed.
fix Ensure file is named exactly 'tsconfig.json', or use a custom prettier override pattern.
npm install prettier-plugin-tsconfig
yarn add prettier-plugin-tsconfig
pnpm add prettier-plugin-tsconfig

Installation and basic usage: install prettier and plugin, add plugin to config, run prettier to format tsconfig.json files.

// Install dependencies
npm install --save-dev prettier prettier-plugin-tsconfig

// Configure .prettierrc
{
  "plugins": ["prettier-plugin-tsconfig"]
}

// Format files
npx prettier --write "**/tsconfig.json"