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.
Common errors
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.
Warnings
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.
Install
npm install prettier-plugin-tsconfig yarn add prettier-plugin-tsconfig pnpm add prettier-plugin-tsconfig Imports
- default wrong
import 'prettier-plugin-tsconfig'correctmodule.exports = { plugins: ['prettier-plugin-tsconfig'] } - Plugin wrong
import { Plugin } from 'prettier-plugin-tsconfig'correctconst plugin = require('prettier-plugin-tsconfig') - prettierConfig wrong
// .prettierrc { "plugin": "prettier-plugin-tsconfig" }correct// .prettierrc { "plugins": ["prettier-plugin-tsconfig"] }
Quickstart
// Install dependencies
npm install --save-dev prettier prettier-plugin-tsconfig
// Configure .prettierrc
{
"plugins": ["prettier-plugin-tsconfig"]
}
// Format files
npx prettier --write "**/tsconfig.json"