esw

raw JSON →
0.15.0 verified Fri May 01 auth: no javascript

esw is a zero-configuration JavaScript/TypeScript library build tool that leverages esbuild for blazing fast performance. Version 0.15.0 is the current stable release, with a moderate release cadence. It infers build options from package.json fields (main, module, type) and automatically excludes dependencies and peerDependencies from the bundle. Unlike tsdx or tsup, esw focuses on minimal configuration and esbuild CLI compatibility. Supports Node.js >=14.14.0 and outputs both CommonJS and ESM formats.

error Error: Could not resolve entry point
cause No source files found at default location (src/index.ts) or specified path is incorrect.
fix
Create src/index.ts or specify entry point explicitly: esw build src/main.ts
error esw: command not found
cause esw is not installed or not in PATH.
fix
Run 'npm install esw --save-dev' and use 'npx esw' or add to scripts in package.json.
error TypeError: Cannot read properties of undefined (reading 'main')
cause package.json is missing or does not have 'main' field when esw tries to infer output.
fix
Ensure package.json exists and contains a 'main' field.
gotcha esw relies on package.json fields. If main/module are not declared, build may produce no output or fail silently.
fix Ensure package.json has 'main' and/or 'module' fields pointing to desired output paths.
gotcha The output format for the 'module' field is always treated as ESM; do not expect CJS for that field.
fix Use 'main' for CommonJS output, 'module' for ESM output.
gotcha esw uses esbuild internally; some esbuild options may not be fully supported or behave differently.
fix Refer to esbuild documentation for option compatibility.
npm install esw
yarn add esw
pnpm add esw

Create a TypeScript library, configure package.json, and run esw build to output both CJS and ESM bundles in dist/ folder.

mkdir my-lib && cd my-lib
npm init -y
npm i esw -D
# Edit package.json to add main/module fields
echo '{"name":"my-lib","main":"dist/index.cjs.js","module":"dist/index.esm.js","scripts":{"build":"esw build"}}' > package.json
mkdir src
echo 'export const add = (a,b) => a+b' > src/index.ts
npm run build
ls dist