{"id":25443,"library":"esbuild-resolve-config","title":"esbuild-resolve-config","description":"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.","status":"active","version":"1.0.9","language":"javascript","source_language":"en","source_url":"ssh://git@github.com/xiaobebe/utils","tags":["javascript","typescript"],"install":[{"cmd":"npm install esbuild-resolve-config","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-resolve-config","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-resolve-config","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Runtime dependency to compile and evaluate TypeScript/JavaScript config files on the fly.","package":"esbuild","optional":false}],"imports":[{"note":"This package uses a default export. Named import will result in undefined.","wrong":"import { resolveConfig } from 'esbuild-resolve-config'","symbol":"resolveConfig (default)","correct":"import resolveConfig from 'esbuild-resolve-config'"},{"note":"CommonJS require returns the default export directly; destructuring will yield undefined.","wrong":"const { resolveConfig } = require('esbuild-resolve-config')","symbol":"resolveConfig (require)","correct":"const resolveConfig = require('esbuild-resolve-config')"},{"note":"TypeScript users should use default import for type safety; the package exports types via its declaration file.","symbol":"resolveConfig (type import)","correct":"import resolveConfig from 'esbuild-resolve-config'"}],"quickstart":{"code":"import resolveConfig from 'esbuild-resolve-config';\n\nasync function main() {\n  try {\n    const config = await resolveConfig('./config.ts');\n    console.log('Resolved config:', config);\n  } catch (error) {\n    console.error('Failed to resolve config:', error);\n  }\n}\n\nmain();","lang":"typescript","description":"Demonstrates how to import and call resolveConfig with a TypeScript config file, handling errors."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure esbuild versions are compatible; consider using a single version via dependency resolution (e.g., npm dedupe or yarn resolutions).","message":"This package bundles esbuild as a dependency, which may lead to version conflicts if your project also uses esbuild with a different version.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use default import: import resolveConfig from 'esbuild-resolve-config' instead of import { resolveConfig }.","message":"Version 1.0.0 changed the API from a named export to a default export. Existing code using named import will break.","severity":"breaking","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Change import to: import resolveConfig from 'esbuild-resolve-config'","cause":"Named import used instead of default import.","error":"TypeError: resolveConfig is not a function"},{"fix":"Install esbuild: npm install esbuild --save-dev","cause":"esbuild is not installed or not in the node_modules tree.","error":"Error: Cannot find module 'esbuild'"},{"fix":"Ensure the config file uses module.exports or default export; check esbuild loader settings if custom.","cause":"The config file uses ES module syntax but the resolver expects a CommonJS export or esbuild handles it incorrectly due to misconfigured loader.","error":"SyntaxError: Unexpected token 'export'"},{"fix":"Verify that esbuild is properly installed and that the file path is correct. Use an absolute path if necessary.","cause":"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.","error":"Error: Dynamic require of \"config.ts\" is not supported"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}