{"id":20033,"library":"find-babel-config","title":"find-babel-config","description":"A lightweight utility to locate the closest Babel configuration file (babel.config.js, babel.config.json, .babelrc, etc.) from a given directory, searching upwards. Version 2.1.2 is stable and actively maintained. It supports both async and sync APIs with config depth control. Compared to alternatives like cosmiconfig, it specializes in Babel configs and has no direct dependency on Babel itself, making it a simple drop-in for Babel-integrated tools. The package is ESM- and CJS-compatible.","status":"active","version":"2.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/tleunen/find-babel-config","tags":["javascript","babel","config","loader","finder","babelrc"],"install":[{"cmd":"npm install find-babel-config","lang":"bash","label":"npm"},{"cmd":"yarn add find-babel-config","lang":"bash","label":"yarn"},{"cmd":"pnpm add find-babel-config","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used to parse .babelrc files that may contain JSON5 syntax.","package":"json5","optional":false},{"reason":"Checks if the config file path exists on the filesystem.","package":"path-exists","optional":false}],"imports":[{"note":"Default export is the async function. In CommonJS, require works fine; no default import distinction.","wrong":"const findBabelConfig = require('find-babel-config')","symbol":"findBabelConfig","correct":"import findBabelConfig from 'find-babel-config'"},{"note":"The sync method is a property of the default export, not a named export.","wrong":"import { sync } from 'find-babel-config'","symbol":"findBabelConfigSync","correct":"import findBabelConfig from 'find-babel-config'; const sync = findBabelConfig.sync"},{"note":"TypeScript types are not exported; you must define the result type yourself.","wrong":"import { Result } from 'find-babel-config'","symbol":"Result","correct":"import findBabelConfig from 'find-babel-config'; type Result = { file: string | null; config: any }"}],"quickstart":{"code":"import findBabelConfig from 'find-babel-config';\n\n// Async usage\nconst directory = process.cwd();\nfindBabelConfig(directory)\n  .then(({ file, config }) => {\n    if (file) {\n      console.log('Found config at:', file);\n      console.log('Config:', JSON.stringify(config, null, 2));\n    } else {\n      console.log('No babel config found');\n    }\n  })\n  .catch(err => {\n    console.error('Error finding config:', err);\n  });\n\n// Sync usage\nconst { file, config } = findBabelConfig.sync(directory);\nif (file) {\n  console.log('Sync found config at:', file);\n}","lang":"typescript","description":"Demonstrates async and sync usage to find the closest babel config from the current directory."},"warnings":[{"fix":"Use promises or async/await instead of callbacks.","message":"In version 2.0.0, the API changed from callback-based to promise-based async.","severity":"breaking","affected_versions":">=1.0.0 <2.0.0"},{"fix":"Wrap sync calls in try-catch.","message":"The sync method may throw errors if the directory does not exist, unlike async which rejects the promise.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use depth=Infinity (default) for unlimited search, or depth=n to search n levels up.","message":"Depth parameter is inclusive: setting depth=1 means only the given directory is searched, no parent.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Use cosmiconfig for broader config file support.","message":"The package does not support Babel configuration as an ES module (babel.config.mjs) or TypeScript (babel.config.ts).","severity":"deprecated","affected_versions":">=2.0.0"},{"fix":"Pass absolute paths to avoid ambiguity.","message":"When using relative directory paths, they are resolved from process.cwd(), not from the module's location.","severity":"gotcha","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":"Run 'npm install find-babel-config' or add to package.json.","cause":"Package not installed or not in node_modules.","error":"Cannot find module 'find-babel-config'"},{"fix":"Use 'const findBabelConfig = require('find-babel-config'); const sync = findBabelConfig.sync;'","cause":"CommonJS require returns the async function; sync is not automatically imported.","error":"findBabelConfig.sync is not a function"},{"fix":"Ensure bundler supports CommonJS interop. Use 'import pkg from 'find-babel-config'; const findBabelConfig = pkg.default || pkg;'","cause":"Default import from ESM might fail if bundler treats it incorrectly.","error":"TypeError: findBabelConfig is not a function"},{"fix":"Verify the directory path exists before calling findBabelConfig.","cause":"The provided directory does not exist.","error":"ENOENT: no such file or directory, scandir '/some/path'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}