rollup-plugin-prettier
raw JSON → 4.1.2 verified Sat Apr 25 auth: no javascript
Rollup plugin to format the final bundle with Prettier. Current stable version is 4.1.2, supports Prettier ^1.0.0 || ^2.0.0 || ^3.0.0 and Rollup ^1.0.0 || ^2.0.0 || ^3.0.0 || ^4.0.0. Ships TypeScript types. Key differentiators: integrates Prettier as a Rollup plugin, handles source map generation by computing diffs. Release cadence is irregular, with recent updates focused on dependency upgrades and Rollup/Prettier version support.
Common errors
error TypeError: prettier is not a function ↓
cause Importing named export instead of default export.
fix
Use import prettier from 'rollup-plugin-prettier' (default import) instead of import { prettier } from 'rollup-plugin-prettier'.
error Error: Cannot find module 'prettier' ↓
cause Prettier is a peer dependency not installed.
fix
Run npm install --save-dev prettier to install it.
error Error: RollupError: Could not resolve 'rollup-plugin-prettier' ↓
cause Plugin not installed.
fix
Run npm install --save-dev rollup-plugin-prettier
error Error: The 'sourceMap' option is deprecated. Use 'sourcemap' instead. ↓
cause Using deprecated camelCase option.
fix
Change sourceMap: true to sourcemap: true in plugin options.
Warnings
breaking In v1.0.0, prettier dependency changed from direct to peer dependency. ↓
fix Install prettier as a devDependency: npm install --save-dev prettier
breaking In v4.0.0, support for prettier ^3.0.0 added; older versions may still work but are not tested. ↓
fix Upgrade plugin to v4.0.0 or later to use prettier v3
deprecated The sourceMap option (camelCase) was deprecated in v1.0.0 in favor of sourcemap (all lowercase). ↓
fix Use sourcemap: true instead of sourceMap: true
gotcha Source map generation may be slow for large bundles because the plugin computes diffs to generate a source map. ↓
fix Disable source map in plugin options if not needed, or accept slower builds.
gotcha The plugin runs Prettier synchronously (before v3.1.0) or asynchronously (v3.1.0+), but this is transparent to the user. ↓
fix No action needed; asynchronous mode prepares for Prettier v3 async API.
Install
npm install rollup-plugin-prettier yarn add rollup-plugin-prettier pnpm add rollup-plugin-prettier Imports
- default wrong
import { prettier } from 'rollup-plugin-prettier'correctimport prettier from 'rollup-plugin-prettier' - default wrong
const { prettier } = require('rollup-plugin-prettier')correctconst prettier = require('rollup-plugin-prettier') - types
import type { PrettierOptions } from 'rollup-plugin-prettier'
Quickstart
import prettier from 'rollup-plugin-prettier';
import { defineConfig } from 'rollup';
export default defineConfig({
input: 'src/index.js',
output: {
file: 'dist/bundle.js',
format: 'es',
},
plugins: [
prettier({
tabWidth: 2,
singleQuote: true,
parser: 'babel',
}),
],
});