Registry / serialization / find-babel-config

find-babel-config

JSON →
library2.1.2jsnpmunverified

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.

npm install find-babel-config
INSTALL
IMPORT
SIG · FIND-BABEL-CONFIG
F
find-babel-config
serializationjavascriptv2.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

findBabelConfig
import findBabelConfig from 'find-babel-config'
const findBabelConfig = require('find-babel-config')
Default export is the async function. In CommonJS, require works fine; no default import distinction.
findBabelConfigSync
import findBabelConfig from 'find-babel-config'; const sync = findBabelConfig.sync
import { sync } from 'find-babel-config'
The sync method is a property of the default export, not a named export.
Result
import findBabelConfig from 'find-babel-config'; type Result = { file: string | null; config: any }
import { Result } from 'find-babel-config'
TypeScript types are not exported; you must define the result type yourself.

Demonstrates async and sync usage to find the closest babel config from the current directory.

import findBabelConfig from 'find-babel-config'; // Async usage const directory = process.cwd(); findBabelConfig(directory) .then(({ file, config }) => { if (file) { console.log('Found config at:', file); console.log('Config:', JSON.stringify(config, null, 2)); } else { console.log('No babel config found'); } }) .catch(err => { console.error('Error finding config:', err); }); // Sync usage const { file, config } = findBabelConfig.sync(directory); if (file) { console.log('Sync found config at:', file); }
Debug
Known issues
breakingIn version 2.0.0, the API changed from callback-based to promise-based async.
fix
Use promises or async/await instead of callbacks.
affects: >=1.0.0 <2.0.0
gotchaThe sync method may throw errors if the directory does not exist, unlike async which rejects the promise.
fix
Wrap sync calls in try-catch.
affects: >=2.0.0
gotchaDepth parameter is inclusive: setting depth=1 means only the given directory is searched, no parent.
fix
Use depth=Infinity (default) for unlimited search, or depth=n to search n levels up.
affects: >=2.0.0
deprecatedThe package does not support Babel configuration as an ES module (babel.config.mjs) or TypeScript (babel.config.ts).
fix
Use cosmiconfig for broader config file support.
affects: >=2.0.0
gotchaWhen using relative directory paths, they are resolved from process.cwd(), not from the module's location.
fix
Pass absolute paths to avoid ambiguity.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'find-babel-config'
Package not installed or not in node_modules.
fix
Run 'npm install find-babel-config' or add to package.json.
findBabelConfig.sync is not a function
CommonJS require returns the async function; sync is not automatically imported.
fix
Use 'const findBabelConfig = require('find-babel-config'); const sync = findBabelConfig.sync;'
TypeError: findBabelConfig is not a function
Default import from ESM might fail if bundler treats it incorrectly.
fix
Ensure bundler supports CommonJS interop. Use 'import pkg from 'find-babel-config'; const findBabelConfig = pkg.default || pkg;'
ENOENT: no such file or directory, scandir '/some/path'
The provided directory does not exist.
fix
Verify the directory path exists before calling findBabelConfig.
Upgrade
Version history
2.1.2latest on npm
Audit
Dependencies
json5requiredUsed to parse .babelrc files that may contain JSON5 syntax.
path-existsrequiredChecks if the config file path exists on the filesystem.
Agent activity
4 hits · last 30 days
node
4
Resources
find-babel-config — npm install find-babel-config · libregistry