{"id":19013,"library":"babel-parse-wild-code","title":"babel-parse-wild-code","description":"Parse user code files using their project's installed Babel version and config, with automatic fallback. Handles JS, TS, TSX, and DTS files with correct parser plugins based on file extension. Supports Babel 7 only. Current stable version 2.1.5 (June 2023). Key differentiator: resolves ambient Babel config per file directory, works around Babel 7 performance bug where parseAsync redoes loadOptionsAsync work. Falls back to @babel/parser defaults if @babel/core or config is missing. Ships ESM and CJS exports with TypeScript definitions. Maintained by codemodsquad.","status":"active","version":"2.1.5","language":"javascript","source_language":"en","source_url":"https://github.com/codemodsquad/babel-parse-wild-code","tags":["javascript","typescript"],"install":[{"cmd":"npm install babel-parse-wild-code","lang":"bash","label":"npm"},{"cmd":"yarn add babel-parse-wild-code","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-parse-wild-code","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency for loading Babel config; fallback to @babel/parser if missing","package":"@babel/core","optional":true},{"reason":"peer dependency for actual parsing; fallback to bundled default if missing","package":"@babel/parser","optional":true}],"imports":[{"note":"ESM export since v2.1.0; CJS require works but named import in ESM is preferred.","wrong":"const parseSync = require('babel-parse-wild-code').parseSync","symbol":"parseSync","correct":"import { parseSync } from 'babel-parse-wild-code'"},{"note":"Named export, not default. Default export does not exist.","wrong":"import parseAsync from 'babel-parse-wild-code'","symbol":"parseAsync","correct":"import { parseAsync } from 'babel-parse-wild-code'"},{"note":"Class constructor; ESM and CJS both supported.","wrong":"const { Parser } = require('babel-parse-wild-code');","symbol":"Parser","correct":"import { Parser } from 'babel-parse-wild-code'"},{"note":"Call before bulk parsing to clear per-directory caches of @babel/core and @babel/parser.","wrong":"","symbol":"clearCache","correct":"import { clearCache } from 'babel-parse-wild-code'"},{"note":"Only top-level named export; no subpath exports.","wrong":"import { getParserSync } from 'babel-parse-wild-code/getParserSync'","symbol":"getParserSync","correct":"import { getParserSync } from 'babel-parse-wild-code'"},{"note":"Async variant of getParserSync; same import path.","wrong":"","symbol":"getParserAsync","correct":"import { getParserAsync } from 'babel-parse-wild-code'"}],"quickstart":{"code":"import { parseSync, clearCache } from 'babel-parse-wild-code'\n\n// Clear cache before bulk operations\nclearCache()\n\n// Parse a TypeScript file synchronously\nconst ast = parseSync('path/to/file.ts')\nconsole.log(ast.program.body)\n\n// Parse with custom parser options (e.g., tokens for jscodeshift)\nconst astWithTokens = parseSync('path/to/file.tsx', { tokens: true, plugins: ['jsx'] })\n\n// Async parsing\nimport { parseAsync } from 'babel-parse-wild-code'\nconst ast2 = await parseAsync('path/to/file.js')\n\n// Get a reusable Parser instance\nimport { getParserSync, Parser } from 'babel-parse-wild-code'\nconst parser: Parser = getParserSync('path/to/file.ts')\nconst parsed = parser.parse('const x: number = 1')\n","lang":"typescript","description":"Demonstrates sync and async parsing with clearCache, custom parser options, and reusable Parser instance for TypeScript files."},"warnings":[{"fix":"Explicitly add these plugins via options.plugins array, or pin to v1.x if you rely on them.","message":"Version 2.0.0 removed default parser plugins for experimental proposals (decorators, doExpressions, exportDefaultFrom, functionBind, pipelineOperator, throwExpressions).","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Upgrade your project to Babel 7, or use an alternative parser.","message":"Babel 6 is not supported; only Babel 7 is supported.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure @babel/core and @babel/parser are installed in the project (not globally) so they can be resolved via require().","message":"If @babel/core or @babel/parser cannot be resolved from the file's directory, the library falls back to bundled default parser options without any project-specific config.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Call clearCache() before each batch of parses, or between batches when config may have changed.","message":"The cache is per-directory and not automatically invalidated on Babel config changes. Clear the cache manually with clearCache() before bulk parsing to avoid stale options.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you pass plugins that conflict with resolved plugins, wrap in a function that filters or deduplicates.","message":"Options passed to parseSync/parseAsync are merged with resolved options for the file, but plugins are concatenated — duplicates are not removed.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Add `tokens: true` to the options object when calling getParserSync/getParserAsync for use with jscodeshift.","message":"When using getParserSync/getParserAsync with jscodeshift, you must pass `{ tokens: true }` in options to include tokens in the AST.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need the old behavior, set `disallowAmbiguousJSXLike: false` in options.","message":"In v2.0.0, the default parser options for .d.ts files changed: disallowAmbiguousJSXLike is now set to true for .d.ts files to conform to TypeScript's parser behavior.","severity":"breaking","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Install @babel/core as a dependency in your project: npm install @babel/core --save","cause":"@babel/core is not installed or not in node_modules path relative to the file being parsed.","error":"Error: Cannot find module '@babel/core'"},{"fix":"Use named import: import { parseSync } from 'babel-parse-wild-code'","cause":"Importing the default export instead of named export, or using wrong module system.","error":"TypeError: (0 , babel-parse-wild-code.parseSync) is not a function"},{"fix":"Pass the missing plugin in options: parseSync('file.jsx', { plugins: ['jsx'] })","cause":"Parsing a file with a syntax that requires a plugin that is not included in the default parser options for that file extension (e.g., JSX in .js file without jsx plugin).","error":"SyntaxError: Unexpected token (1:0)"},{"fix":"Upgrade @babel/parser to version 7.13.0 or later: npm install @babel/parser@latest","cause":"Using an older version of @babel/parser that does not support certain options that babel-parse-wild-code sets for .d.ts files.","error":"Error: @babel/parser: Option 'allowUndeclaredExports' is not registered"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}