Registry / http-networking / esbuild-resolve-config

esbuild-resolve-config

JSON →
library1.0.9jsnpmunverified

A utility to load and resolve JavaScript/TypeScript configuration files using esbuild. It reads configuration from .js, .ts, .mjs, or .cjs files, compiles them on-the-fly with esbuild, and returns the exported config object. Useful for tools that need to consume user config files (e.g., bundler plugins, CLI tools). Version 1.0.9 ships TypeScript type definitions and has no external dependencies beyond esbuild. Released under MIT license. Different from other config resolvers (like cosmiconfig) by leveraging esbuild for fast and correct TypeScript/ESM compilation.

npm install esbuild-resolve-config
INSTALL
IMPORT
SIG · ESBUILD-RESOLVE-CO
E
esbuild-resolve-config
http-networkingjavascriptv1.0.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

resolveConfig (default)
✓ import resolveConfig from 'esbuild-resolve-config'
✗ import { resolveConfig } from 'esbuild-resolve-config'
This package uses a default export. Named import will result in undefined.
resolveConfig (require)
✓ const resolveConfig = require('esbuild-resolve-config')
✗ const { resolveConfig } = require('esbuild-resolve-config')
CommonJS require returns the default export directly; destructuring will yield undefined.
resolveConfig (type import)
✓ import resolveConfig from 'esbuild-resolve-config'
TypeScript users should use default import for type safety; the package exports types via its declaration file.

Demonstrates how to import and call resolveConfig with a TypeScript config file, handling errors.

import resolveConfig from 'esbuild-resolve-config'; async function main() { try { const config = await resolveConfig('./config.ts'); console.log('Resolved config:', config); } catch (error) { console.error('Failed to resolve config:', error); } } main();
Debug
Known issues
gotchaThe resolved config is evaluated via esbuild's transform, not via Node's module system. This means the config file must be self-contained (no Node.js built-ins unless polyfilled) and runs in a sandboxed environment.
fix
Ensure the config file does not rely on Node.js globals (e.g., process, require) unless they are provided by esbuild's define or inject features.
affects: >=1.0.0
gotchaThis package bundles esbuild as a dependency, which may lead to version conflicts if your project also uses esbuild with a different version.
fix
Ensure esbuild versions are compatible; consider using a single version via dependency resolution (e.g., npm dedupe or yarn resolutions).
affects: >=1.0.0
breakingVersion 1.0.0 changed the API from a named export to a default export. Existing code using named import will break.
fix
Use default import: import resolveConfig from 'esbuild-resolve-config' instead of import { resolveConfig }.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: resolveConfig is not a function
Named import used instead of default import.
fix
Change import to: import resolveConfig from 'esbuild-resolve-config'
Error: Cannot find module 'esbuild'
esbuild is not installed or not in the node_modules tree.
fix
Install esbuild: npm install esbuild --save-dev
SyntaxError: Unexpected token 'export'
The config file uses ES module syntax but the resolver expects a CommonJS export or esbuild handles it incorrectly due to misconfigured loader.
fix
Ensure the config file uses module.exports or default export; check esbuild loader settings if custom.
Error: Dynamic require of "config.ts" is not supported
The config file path resolves to a .ts file but the current Node.js version does not support TypeScript natively, and the resolver fails to invoke esbuild.
fix
Verify that esbuild is properly installed and that the file path is correct. Use an absolute path if necessary.
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies
esbuildrequiredRuntime dependency to compile and evaluate TypeScript/JavaScript config files on the fly.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
esbuild-resolve-config — npm install esbuild-resolve-config · libregistry