Registry / devops / esbuild-plugin-prettier

esbuild-plugin-prettier

JSON →
library1.0.0jsnpmunverified

An esbuild plugin that automatically formats processed files with Prettier. Version 1.0.0 is the initial release. It runs Prettier on each file that matches the filter regex (default: /[jt]sx?|s?css/) and writes changes back. This plugin is useful in watch mode to keep code formatted without manual intervention. It is lightweight and configurable, but note that Prettier rewriting may conflict with esbuild's incremental build caching.

npm install esbuild-plugin-prettier
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-PRE
E
esbuild-plugin-prettier
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import esbuildPluginPrettier from 'esbuild-plugin-prettier'
const esbuildPluginPrettier = require('esbuild-plugin-prettier')
Package ships as ESM. Use dynamic import if in CommonJS context.
esbuildPluginPrettier (default)
import plugin from 'esbuild-plugin-prettier'
import { plugin } from 'esbuild-plugin-prettier'
The default export is the plugin function; no named exports.
type Options
import type { Options } from 'esbuild-plugin-prettier'
Options type is exported for TypeScript users, but not required.

Demonstrates using the plugin in an esbuild build with custom filter and Prettier options.

import esbuild from 'esbuild'; import prettierPlugin from 'esbuild-plugin-prettier'; await esbuild.build({ entryPoints: ['src/index.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [ prettierPlugin({ filter: /\.js$/, prettierOptions: { semi: false, singleQuote: true, }, }), ], }); console.log('Build complete with Prettier formatting!');
Debug
Known issues
gotchaPrettier rewriting files can invalidate esbuild's cache on every rebuild, slowing down watch mode.
fix
Consider disabling the plugin for production builds or using onEnd instead of onLoad.
affects: >=1.0.0
deprecatedThe plugin uses prettier's sync API internally; large files may block the event loop.
fix
Use prettier's asynchronous API if performance is critical; consider an alternative plugin.
affects: >=1.0.0
gotchaDefault filter includes CSS and SCSS files, but prettier may not have a parser for them unless configured.
fix
Set filter to only include file types you have prettier plugins installed for.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'prettier'
Missing peer dependency 'prettier'
fix
Run: npm install prettier
TypeError: prettier.format is not a function
Using a version of prettier that does not export 'format' (prettier v3+ uses ESM default export)
fix
Use prettier v2 or configure the plugin to work with prettier v3 (requires plugin update)
Error: No matching files found for filter: /[jt]sx?|s?css/
Plugin filter regex does not match any input files
fix
Specify a custom filter that matches your file extensions
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
prettierrequiredpeer dependency required at runtime for formatting files
Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-prettier — npm install esbuild-plugin-prettier · libregistry