{"id":19067,"library":"babel-plugin-generator-prettier","title":"babel-plugin-generator-prettier","description":"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.","status":"active","version":"1.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/goto-bus-stop/babel-plugin-generator-prettier","tags":["javascript","ast","babel","babel-generator","babel-plugin","beautify","code-generator","format","generator"],"install":[{"cmd":"npm install babel-plugin-generator-prettier","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-generator-prettier","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-generator-prettier","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Babel plugin requires Babel 7 as host","package":"@babel/core","optional":false},{"reason":"Used to format transformed code","package":"prettier","optional":false}],"imports":[{"note":"Plugin is typically used without importing; configured in .babelrc or babel.config.js. If importing for programmatic use, use default import.","wrong":"const babelPluginGeneratorPrettier = require('babel-plugin-generator-prettier')","symbol":"babelPluginGeneratorPrettier","correct":"import babelPluginGeneratorPrettier from 'babel-plugin-generator-prettier'"},{"note":"In .babelrc or babel.config.js, the package is referenced by its short name (without 'babel-plugin-').","wrong":"plugins: ['babel-plugin-generator-prettier']","symbol":"plugin","correct":"plugins: ['generator-prettier']"},{"note":"Prettier options are passed via the `generatorOpts` top-level key in Babel config, not inside the plugin config.","wrong":"","symbol":"generatorOpts","correct":"generatorOpts: { printWidth: 120 }"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\"generator-prettier\"],\n  \"generatorOpts\": {\n    \"printWidth\": 80,\n    \"semi\": true,\n    \"singleQuote\": true,\n    \"trailingComma\": \"all\",\n    \"tabWidth\": 2\n  }\n}\n\n// In your build script (if using Node API)\nconst babel = require('@babel/core');\nbabel.transformSync('const x = 1', {\n  plugins: ['generator-prettier'],\n  generatorOpts: {\n    printWidth: 80,\n    semi: true,\n    singleQuote: true,\n    trailingComma: 'all',\n    tabWidth: 2\n  }\n});","lang":"javascript","description":"Configures the plugin in .babelrc to format output with Prettier using custom print width, semicolons, single quotes, trailing commas, and tab width."},"warnings":[{"fix":"Use generatorOpts top-level key in Babel config; avoid passing options inside the plugin array.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to Babel 7 or use an alternative for Babel 6.","message":"Requires Babel 7; incompatible with Babel 6.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Consider using prettier directly via CLI or API after Babel transformation.","message":"Prettier's own Babel integration (prettier/@babel/code-frame) may supersede this plugin.","severity":"deprecated","affected_versions":"all"},{"fix":"Upgrade to v1.1.0 or later for source map support.","message":"Source maps are supported only since v1.1.0; older versions lose source maps.","severity":"gotcha","affected_versions":"<1.1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run `npm install babel-plugin-generator-prettier` and ensure the plugin name is correct (e.g., 'generator-prettier' in .babelrc).","cause":"The plugin is not installed or is listed incorrectly in Babel config.","error":"Error: Cannot find module 'babel-plugin-generator-prettier'"},{"fix":"Upgrade to Babel 7: `npm install @babel/core @babel/cli` and update config files.","cause":"The project uses Babel 6.","error":"Error: Plugin generator-prettier requires Babel 7"},{"fix":"Install Prettier v2+: `npm install prettier@2`.","cause":"Incompatible Prettier version (pre-v2 API). The plugin expects the modern prettier.format function.","error":"TypeError: prettier.format is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}