Prettier Preset
raw JSON → 1.0.1 verified Sat Apr 25 auth: no javascript
A sharable configuration preset for Prettier, enabling consistent code formatting across projects. Version 1.0.1 is the latest stable release; development appears sporadic. It differentiates by providing a drop-in preset instead of requiring manual config setup. Currently limited to a single preset with no options to customize. Suitable for teams wanting a standardized Prettier config quickly.
Common errors
error Error: Invalid configuration file '.prettierrc.js': Expected an object but got a string. ↓
cause Using module.exports = require('prettier-preset') which yields the string 'prettier-preset'.
fix
Use module.exports = 'prettier-preset'; (string literal) or set "prettier": "prettier-preset" in package.json.
error Cannot find module 'prettier-preset' ↓
cause prettier-preset is not installed or not in node_modules.
fix
Run npm install --save-dev prettier-preset (or yarn add --dev prettier-preset).
error Unexpected token export (or similar ESM import error) ↓
cause Attempting to import preset using ES modules import (e.g., import preset from 'prettier-preset'). Package is CJS-only.
fix
Use require('prettier-preset') for programmatic access, or use the package.json string method.
Warnings
gotcha The preset is not extensible; you cannot override specific options. ↓
fix Use a different approach (e.g., shareable config in .prettierrc.js) if customization is needed.
gotcha This package exports a string, not an object. Using require() in a config file expecting an object will trigger a Prettier error. ↓
fix Set 'prettier' field in package.json to the package name string, or use a .prettierrc.js that returns a string.
deprecated The package has not been updated since initial release. May not support latest Prettier options. ↓
fix Consider forking or creating your own preset.
Install
npm install prettier-preset yarn add prettier-preset pnpm add prettier-preset Imports
- preset (via package.json) wrong
Using .prettierrc.js with `module.exports = require('prettier-preset')` (not supported)correctIn package.json: "prettier": "prettier-preset" - Default config (require) wrong
module.exports = require('prettier-preset'); // exports string not objectcorrectIn .prettierrc.js: module.exports = 'prettier-preset'; - Import for programmatic use wrong
import preset from 'prettier-preset'; // ESM not supportedcorrectconst preset = require('prettier-preset'); // returns string 'prettier-preset'
Quickstart
// Install
$ yarn add --dev prettier prettier-preset
// package.json
{
"name": "my-project",
"version": "1.0.0",
"prettier": "prettier-preset"
}
// Then run prettier on files
$ npx prettier --write src/