Registry / devops / babel-plugin-generator-prettier

babel-plugin-generator-prettier

JSON →
library1.2.0jsnpmunverified

A Babel plugin that replaces the default code generator with Prettier for prettier transformed output. It allows passing Prettier options (e.g., printWidth, semi) via generatorOpts in Babel config. Requires Babel 7 and Prettier. Supports source maps since v1.1.0. Lightweight and zero-config alternative to running Prettier as a separate step.

npm install babel-plugin-generator-prettier
INSTALL
IMPORT
SIG · BABEL-PLUGIN-GENER
B
babel-plugin-generator-prettier
devopsjavascriptv1.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

babelPluginGeneratorPrettier
import babelPluginGeneratorPrettier from 'babel-plugin-generator-prettier'
const babelPluginGeneratorPrettier = require('babel-plugin-generator-prettier')
Plugin is typically used without importing; configured in .babelrc or babel.config.js. If importing for programmatic use, use default import.
plugin
plugins: ['generator-prettier']
plugins: ['babel-plugin-generator-prettier']
In .babelrc or babel.config.js, the package is referenced by its short name (without 'babel-plugin-').
generatorOpts
generatorOpts: { printWidth: 120 }
Prettier options are passed via the `generatorOpts` top-level key in Babel config, not inside the plugin config.

Configures the plugin in .babelrc to format output with Prettier using custom print width, semicolons, single quotes, trailing commas, and tab width.

// .babelrc { "plugins": ["generator-prettier"], "generatorOpts": { "printWidth": 80, "semi": true, "singleQuote": true, "trailingComma": "all", "tabWidth": 2 } } // In your build script (if using Node API) const babel = require('@babel/core'); babel.transformSync('const x = 1', { plugins: ['generator-prettier'], generatorOpts: { printWidth: 80, semi: true, singleQuote: true, trailingComma: 'all', tabWidth: 2 } });
Debug
Known issues
gotchaThe plugin does not support all Prettier options; only those relevant to code formatting (e.g., no parser or filepath options). Options are passed via generatorOpts key, not plugin options.
fix
Use generatorOpts top-level key in Babel config; avoid passing options inside the plugin array.
affects: >=1.0.0
breakingRequires Babel 7; incompatible with Babel 6.
fix
Upgrade to Babel 7 or use an alternative for Babel 6.
affects: >=1.0.0
deprecatedPrettier's own Babel integration (prettier/@babel/code-frame) may supersede this plugin.
fix
Consider using prettier directly via CLI or API after Babel transformation.
affects: all
gotchaSource maps are supported only since v1.1.0; older versions lose source maps.
fix
Upgrade to v1.1.0 or later for source map support.
affects: <1.1.0
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-generator-prettier'
The plugin is not installed or is listed incorrectly in Babel config.
fix
Run `npm install babel-plugin-generator-prettier` and ensure the plugin name is correct (e.g., 'generator-prettier' in .babelrc).
Error: Plugin generator-prettier requires Babel 7
The project uses Babel 6.
fix
Upgrade to Babel 7: `npm install @babel/core @babel/cli` and update config files.
TypeError: prettier.format is not a function
Incompatible Prettier version (pre-v2 API). The plugin expects the modern prettier.format function.
fix
Install Prettier v2+: `npm install prettier@2`.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies
@babel/corerequiredBabel plugin requires Babel 7 as host
prettierrequiredUsed to format transformed code
Agent activity
6 hits · last 30 days
node
6
Resources
babel-plugin-generator-prettier — npm install babel-plugin-generator-prettier · libregistry