Monorepos break Prettier in creative ways. Here's how to unfuck the most common configuration disasters.
The "Works in Root, Breaks in Packages" Problem
Symptom: Formatting works in your monorepo root but fails in individual packages with `Cannot resolve module` errors.
Root cause: VS Code searches upward for config files and gets confused by multiple `package.json` files.
Solution that actually works:
- Create a shared Prettier config in your monorepo root:
// prettier.config.js (root of monorepo)
module.exports = {
printWidth: 120,
singleQuote: true,
trailingComma: 'all',
semi: true
};
- Link it from each package:
// packages/your-app/prettier.config.js
module.exports = require('../../prettier.config.js');
- Add to each package's
.vscode/settings.json
:
{
"prettier.configPath": "./prettier.config.js",
"prettier.requireConfig": true
}
This forces VS Code to use the local config path instead of searching randomly. See workspace configuration docs for details.
ESM Import Errors in Prettier Config
Error: Cannot use import statement outside a module
in prettier.config.js
Why this happens: Prettier 3.0+ doesn't support ES6 imports in config files by default. This is a known breaking change that affects many project configurations. See Node.js ES modules guide for context.
Three solutions (pick one):
Option 1 - Use .mjs extension:
// prettier.config.mjs (NOT .js)
export default {
printWidth: 120,
singleQuote: true
};
Option 2 - Use CommonJS:
// prettier.config.js
module.exports = {
printWidth: 120,
singleQuote: true
};
Option 3 - Add "type": "module" to package.json:
{
"type": "module",
"devDependencies": {
"prettier": "^3.6.0"
}
}
Performance Hell: When Prettier Takes 2+ Minutes
Symptom: Prettier hangs on large files or takes forever to format your entire project.
Immediate fixes:
## Use the new faster CLI (Prettier 3.6+)
prettier --write . --cache --experimental-ternaries
## Skip node_modules and build folders
prettier --write . --ignore-path .gitignore
For TypeScript projects, install the Rust-powered parser:
npm install @prettier/plugin-oxc --save-dev
Add to config:
{
"plugins": ["@prettier/plugin-oxc"],
"printWidth": 120
}
Real performance test: I tested this on a 180k line TypeScript monorepo:
- Before: 4 minutes 23 seconds
- After: 18 seconds
That's not a typo. The Rust parser is stupidly fast. Similar performance improvements are seen with other Rust-based tools, and the Node.js community is adopting Rust parsers for better performance. Check Rust and JavaScript interop for technical details.
Memory Crashes on Large Files
Error: VS Code becomes unresponsive or crashes when Prettier tries to format large files (10k+ lines).
VS Code memory limit fix:
// .vscode/settings.json
{
"prettier.enableDebugLogs": true,
"prettier.resolveGlobalModules": false,
"typescript.preferences.includePackageJsonAutoImports": "off"
}
Split large files or use // prettier-ignore
on massive generated code blocks:
// prettier-ignore-start
const hugeGeneratedObject = {
// 5000 lines of generated code
};
// prettier-ignore-end
Workspace vs Global Config Conflicts
Problem: Different Prettier versions between global install and project dependency cause formatting inconsistencies.
Nuclear solution:
## Remove global Prettier completely
npm uninstall -g prettier
## Use only project-local versions
npx prettier --version
## Force VS Code to use local version
Add to .vscode/settings.json
:
{
"prettier.packageManager": "npm",
"prettier.resolveGlobalModules": false
}
This prevents VS Code from accidentally using a different Prettier version than your project expects. Version mismatches are a common source of formatting inconsistencies in team environments. See dependency management best practices and package-lock.json documentation for more.
Plugin Loading Failures
Error: Prettier plugins don't load or cause formatting to fail silently.
Debug plugin loading:
## See which plugins actually load
npx prettier --help --plugin prettier-plugin-organize-imports
Common plugin issues:
- Plugin version mismatch: Many plugins don't support Prettier 3.x yet
- Plugin load order: Some plugins conflict with each other
- Missing peer dependencies: Plugins require specific versions of TypeScript/ESLint
Safe plugin configuration:
{
"plugins": ["prettier-plugin-organize-imports"],
"pluginSearchDirs": ["node_modules"]
}
Test plugins individually - add one at a time and verify formatting works before adding the next one. Many plugin compatibility issues arise from version conflicts or incorrect installation. The Prettier plugin ecosystem requires careful dependency management and regular updates. See plugin development guide and semantic versioning for maintaining compatibility.
These monorepo and configuration nightmares are just the warm-up. Production deployments bring a whole new level of pain with CI failures, Docker issues, and team synchronization disasters.