{"id":19353,"library":"babel-prettier-parser","title":"babel-prettier-parser","description":"A Prettier parser wrapper that enables formatting of JavaScript/TypeScript code containing experimental or non-standard syntaxes that Babel can transform, such as pipeline operators, decorators, and do expressions. Version 0.10.8 is the latest stable release with no fixed release cadence. It ships TypeScript types and requires Prettier ^2.2.1 as a peer dependency. Unlike Prettier's default Babel parser, this package allows parsing of code with Babel plugins that are not included by default in Prettier, making it suitable for projects using advanced ECMAScript proposals. However, it is a niche tool with limited community adoption and may have compatibility issues with future Prettier versions.","status":"active","version":"0.10.8","language":"javascript","source_language":"en","source_url":"https://github.com/mofon-design/renderer","tags":["javascript","babel","prettier","parser","typescript"],"install":[{"cmd":"npm install babel-prettier-parser","lang":"bash","label":"npm"},{"cmd":"yarn add babel-prettier-parser","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-prettier-parser","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required for parsing functionality","package":"prettier","optional":false}],"imports":[{"note":"ESM-only since v0.10.0; TypeScript types included.","wrong":"const { parse } = require('babel-prettier-parser')","symbol":"parse","correct":"import { parse } from 'babel-prettier-parser'"},{"note":"Default export is an object with parse method; named export `parse` is preferred.","wrong":"import { default as parse } from 'babel-prettier-parser'","symbol":"default","correct":"import bpParser from 'babel-prettier-parser'; bpParser.parse(source)"},{"note":"Named constant for passing options to Babel; not a default export.","wrong":"import BABEL_PARSER_OPTIONS from 'babel-prettier-parser'","symbol":"BABEL_PARSER_OPTIONS","correct":"import { BABEL_PARSER_OPTIONS } from 'babel-prettier-parser'"}],"quickstart":{"code":"import prettier from 'prettier';\nimport { parse } from 'babel-prettier-parser';\n\nconst code = `const x = do { if (true) 1; else 2; };`;\n\n// Register the parser with Prettier\nprettier.format(code, {\n  parser: 'babel',\n  plugins: [{\n    parsers: {\n      babel: {\n        parse: (text, parsers) => {\n          const ast = parse(text, {\n            plugins: ['doExpressions'],\n            sourceType: 'module',\n          });\n          // Transform AST to Prettier-compatible AST if needed\n          return ast;\n        },\n      },\n    },\n  }],\n}).then(result => console.log(result));","lang":"typescript","description":"Demonstrates configuring Prettier to use babel-prettier-parser for formatting code with do expressions."},"warnings":[{"fix":"Access the root node via result.ast or similar; check the updated API.","message":"Version 0.8.0: parse now returns an object with a `type` property. Old code expects an AST node.","severity":"breaking","affected_versions":">=0.8.0"},{"fix":"Use { code: source } instead of { text: source }.","message":"The `text` parameter in parse has been deprecated in favor of `code`.","severity":"deprecated","affected_versions":">=0.9.0"},{"fix":"Always pass the required Babel plugins in the options object to parse.","message":"The parser does not support all Prettier options; custom Babel plugins must be passed explicitly.","severity":"gotcha","affected_versions":"all"}],"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-prettier-parser --save-dev","cause":"Package not installed or missed in dependencies.","error":"Cannot find module 'babel-prettier-parser'"},{"fix":"Use import syntax or dynamic import().","cause":"CJS require not supported for ESM-only package.","error":"Must use import to load ES Module: require() of ES modules is not supported"},{"fix":"Use { parse } instead of default import.","cause":"Default import is an object, not a function.","error":"TypeError: parse is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}