Registry / serialization / babel-prettier-parser

babel-prettier-parser

JSON →
library0.10.8jsnpmunverified

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.

npm install babel-prettier-parser
INSTALL
IMPORT
SIG · BABEL-PRETTIER-PAR
B
babel-prettier-parser
serializationjavascriptv0.10.8
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

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

parse
✓ import { parse } from 'babel-prettier-parser'
✗ const { parse } = require('babel-prettier-parser')
ESM-only since v0.10.0; TypeScript types included.
default
✓ import bpParser from 'babel-prettier-parser'; bpParser.parse(source)
✗ import { default as parse } from 'babel-prettier-parser'
Default export is an object with parse method; named export `parse` is preferred.
BABEL_PARSER_OPTIONS
✓ import { BABEL_PARSER_OPTIONS } from 'babel-prettier-parser'
✗ import BABEL_PARSER_OPTIONS from 'babel-prettier-parser'
Named constant for passing options to Babel; not a default export.

Demonstrates configuring Prettier to use babel-prettier-parser for formatting code with do expressions.

import prettier from 'prettier'; import { parse } from 'babel-prettier-parser'; const code = `const x = do { if (true) 1; else 2; };`; // Register the parser with Prettier prettier.format(code, { parser: 'babel', plugins: [{ parsers: { babel: { parse: (text, parsers) => { const ast = parse(text, { plugins: ['doExpressions'], sourceType: 'module', }); // Transform AST to Prettier-compatible AST if needed return ast; }, }, }, }], }).then(result => console.log(result));
Debug
Known issues
breakingVersion 0.8.0: parse now returns an object with a `type` property. Old code expects an AST node.
fix
Access the root node via result.ast or similar; check the updated API.
affects: >=0.8.0
deprecatedThe `text` parameter in parse has been deprecated in favor of `code`.
fix
Use { code: source } instead of { text: source }.
affects: >=0.9.0
gotchaThe parser does not support all Prettier options; custom Babel plugins must be passed explicitly.
fix
Always pass the required Babel plugins in the options object to parse.
affects: all
Errors
Common errors & fixes
Cannot find module 'babel-prettier-parser'
Package not installed or missed in dependencies.
fix
Run npm install babel-prettier-parser --save-dev
Must use import to load ES Module: require() of ES modules is not supported
CJS require not supported for ESM-only package.
fix
Use import syntax or dynamic import().
TypeError: parse is not a function
Default import is an object, not a function.
fix
Use { parse } instead of default import.
Upgrade
Version history
0.10.8latest on npm
Audit
Dependencies
prettierrequiredpeer dependency required for parsing functionality
Agent activity
24 hits · last 30 days
node
20
OpenAI (training)
1
Resources
babel-prettier-parser — npm install babel-prettier-parser · libregistry