{"id":20016,"library":"estree-to-babel","title":"estree-to-babel","description":"Converts ESTree-compatible JavaScript AST (from parsers like acorn, cherow, espree) to Babel AST for use with tools like @babel/traverse, @babel/types, etc. Current stable version is v12.0.1, released in 2025. Requires Node >=22 and ships TypeScript types. Key differentiators: handles differences between ESTree and Babel AST (Literal vs StringLiteral, ChainExpression vs OptionalMemberExpression, etc.), TypeScript-ESTree specifics (ClassPrivateProperty, TSQualifiedName), and provides convertParens option to control parenthesization. ESM-only since v12, dropping CommonJS support.","status":"active","version":"12.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/coderaiser/estree-to-babel","tags":["javascript","ast","convert","estree","babel","espree","typescript"],"install":[{"cmd":"npm install estree-to-babel","lang":"bash","label":"npm"},{"cmd":"yarn add estree-to-babel","lang":"bash","label":"yarn"},{"cmd":"pnpm add estree-to-babel","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v12.0.0; CommonJS require will fail.","wrong":"const estreeToBabel = require('estree-to-babel')","symbol":"estreeToBabel","correct":"import { estreeToBabel } from 'estree-to-babel'"},{"note":"The default export is also the estreeToBabel function. Avoid named import 'convert'.","wrong":"import { convert } from 'estree-to-babel'","symbol":"estreeToBabel default export","correct":"import convert from 'estree-to-babel'"},{"note":"Type import to avoid bundling. Options type is exported since v11.0.2.","wrong":"import { EstreeToBabelOptions } from 'estree-to-babel'","symbol":"for TypeScript types","correct":"import type { EstreeToBabelOptions } from 'estree-to-babel'"}],"quickstart":{"code":"import { parse } from 'cherow';\nimport { estreeToBabel } from 'estree-to-babel';\nimport { traverse } from '@babel/traverse';\n\nconst source = `\nconst f = ({a}) => a;\n`;\n\nconst estreeAst = parse(source);\nconst babelAst = estreeToBabel(estreeAst);\n\ntraverse(babelAst, {\n  ObjectProperty(path) {\n    console.log(path.node.key.name);\n    // output: 'a'\n  },\n});","lang":"typescript","description":"Parses JavaScript with cherow, converts to Babel AST, and traverses using @babel/traverse."},"warnings":[{"fix":"Use import statements instead of require(). If you need CommonJS, stay on v11.x.","message":"v12.0.0 dropped CommonJS support; package is ESM-only. require() will throw ERR_REQUIRE_ESM.","severity":"breaking","affected_versions":">=12.0.0"},{"fix":"Upgrade Node.js to >=22.0.0.","message":"v12.0.0 dropped support for Node < 22. Older Node versions will produce runtime errors.","severity":"breaking","affected_versions":">=12.0.0"},{"fix":"Clone the input AST before passing to estreeToBabel if you need the original.","message":"The function mutates the input AST object; it does not return a new copy. Be careful if you need to keep the original ESTree AST.","severity":"gotcha","affected_versions":"*"},{"fix":"Explicitly set convertParens: true/false to future-proof your code.","message":"convertParens option default will change in future versions; currently defaults to true (parenthesized expressions are converted).","severity":"deprecated","affected_versions":">=10.5.0 <13.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Add 'type': 'module' to package.json or use .mjs extension.","cause":"Using ESM import syntax with CommonJS project (no 'type': 'module' in package.json).","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Use import { estreeToBabel } from 'estree-to-babel' (ESM) or require('estree-to-babel').default (CJS, but not recommended).","cause":"Using require('estree-to-babel') which returns a module object, not the function directly. For CommonJS, use require('estree-to-babel').default or stay on v11.","error":"TypeError: estreeToBabel is not a function"},{"fix":"Run 'npm install estree-to-babel' and ensure node_modules is present.","cause":"Missing npm install or incorrect path.","error":"Module not found: Can't resolve 'estree-to-babel'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}