{"id":12937,"library":"bunchee","title":"Bunchee: Zero-config JavaScript/TypeScript Bundler","description":"Bunchee is a zero-configuration JavaScript/TypeScript bundler designed specifically for libraries and packages. It streamlines the build process by leveraging the `exports` field within `package.json` as the single source of truth for entry points and output formats. Powered by Rollup for bundling and SWC for fast transpilation, Bunchee automatically aligns entry file conventions from `src/` directories with declared exports, supporting both CommonJS and ESModules. The current stable version is 6.10.0, with frequent patch and minor releases indicating active development. Its key differentiators include its zero-config approach and deep integration with `package.json#exports` for intuitive and efficient package builds, minimizing boilerplate configuration commonly found in other bundlers.","status":"active","version":"6.10.0","language":"javascript","source_language":"en","source_url":"https://github.com/huozhi/bunchee","tags":["javascript","bundler","bundle","typescript","jsx","zero-config","library","css"],"install":[{"cmd":"npm install bunchee","lang":"bash","label":"npm"},{"cmd":"yarn add bunchee","lang":"bash","label":"yarn"},{"cmd":"pnpm add bunchee","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required for compiling TypeScript source code and generating type declarations. Declared as a peer dependency.","package":"typescript","optional":false}],"imports":[{"note":"The primary usage of Bunchee is via its CLI, typically through `package.json` scripts. This named export is for programmatic integration in custom build setups within an ES Module environment.","wrong":"const bunchee = require('bunchee')","symbol":"bunchee","correct":"import { bunchee } from 'bunchee'"},{"note":"Type import for configuring Bunchee programmatically. Using `import type` is recommended to prevent type imports from being bundled as runtime code.","wrong":"import { BuncheeRollupConfig } from 'bunchee'","symbol":"BuncheeRollupConfig","correct":"import type { BuncheeRollupConfig } from 'bunchee'"}],"quickstart":{"code":"{\n  \"name\": \"my-awesome-lib\",\n  \"version\": \"1.0.0\",\n  \"type\": \"module\",\n  \"main\": \"./dist/index.js\",\n  \"scripts\": {\n    \"build\": \"bunchee\"\n  },\n  \"exports\": {\n    \".\": {\n      \"import\": \"./dist/index.js\",\n      \"require\": \"./dist/index.cjs\",\n      \"types\": \"./dist/index.d.ts\"\n    },\n    \"./utils\": {\n      \"import\": \"./dist/utils.js\",\n      \"require\": \"./dist/utils.cjs\",\n      \"types\": \"./dist/utils.d.ts\"\n    }\n  },\n  \"devDependencies\": {\n    \"bunchee\": \"^6.0.0\",\n    \"typescript\": \"^5.0.0\"\n  }\n}\n\n// --- src/index.ts ---\n// This is the main entry point for the library.\nexport * from './utils';\nexport const greet = (name: string): string => `Hello, ${name}!`;\n\n// --- src/utils.ts ---\n// An example of a utility module to be exported separately.\nexport const add = (a: number, b: number): number => a + b;\n\n// To run this quickstart:\n// 1. Create a new directory, e.g., 'my-awesome-lib'.\n// 2. Inside, create a `package.json` file and paste the JSON content above.\n// 3. Create a `src` directory, then `src/index.ts` and `src/utils.ts` files with the TypeScript code.\n// 4. Install dependencies: `npm install` or `pnpm install`.\n// 5. Run the build command: `npm run build`.\n// This will generate bundled output files (e.g., `dist/index.js`, `dist/index.cjs`, `dist/index.d.ts`) in the `dist` directory.","lang":"typescript","description":"Demonstrates how to set up `bunchee` to build a simple TypeScript library with `package.json#exports` for multiple entry points and type declarations."},"warnings":[{"fix":"Thoroughly review the 'Entry Files' and 'Output Formats' sections of the Bunchee documentation. Ensure your `package.json#exports` field accurately maps your source files in `src/` to their desired output paths and formats.","message":"Bunchee heavily relies on the `exports` field in `package.json` to determine entry points, output formats (ESM/CJS), and type declaration paths. Misconfiguration or an incomplete `exports` field can lead to unexpected build outputs, missing modules, or runtime errors.","severity":"gotcha","affected_versions":">=6.0.0"},{"fix":"Install a compatible version of TypeScript in your project: `npm install --save-dev typescript@'^(4.1 || 5.0 || 6.0)'` or `pnpm add -D typescript@'^(4.1 || 5.0 || 6.0)'`.","message":"Bunchee declares TypeScript as a peer dependency. You must install a compatible version (e.g., `^4.1 || ^5.0 || ^6.0`) in your project's `devDependencies`. Failure to do so, or using an incompatible version, can lead to compilation failures.","severity":"breaking","affected_versions":">=6.0.0"},{"fix":"Upgrade your Node.js environment to version 18.0.0 or newer. Use a Node.js version manager (e.g., `nvm`) to easily switch versions if necessary.","message":"Bunchee requires Node.js version 18.0.0 or higher to run. Executing Bunchee with older Node.js versions will result in execution failures, as indicated by the `package.json#engines` field.","severity":"breaking","affected_versions":">=6.0.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install TypeScript in your project: `npm install --save-dev typescript` or `pnpm add -D typescript`.","cause":"TypeScript is declared as a peer dependency for Bunchee, but it is not installed in your project's `devDependencies`.","error":"Error: Cannot find module 'typescript'"},{"fix":"Verify that your `package.json#exports` configuration precisely matches the actual paths and names of your source entry files (e.g., ensure `src/index.ts` exists and corresponds to the `.` export).","cause":"The `package.json#exports` field does not correctly map to your source entry files in the `src` directory, or the specified source file does not exist at the expected path.","error":"RollupError: Could not resolve entry module (./src/index.ts) from package.json exports."},{"fix":"If using Bunchee programmatically, ensure you are in an ES Module context and use `import { bunchee } from 'bunchee'`. If you intend to use the CLI, ensure it's invoked correctly via `package.json` scripts (e.g., `\"build\": \"bunchee\"`).","cause":"This error typically occurs when attempting to use `bunchee` programmatically with an incorrect import statement (e.g., CommonJS `require` in an ESM context, or a default import when a named import is expected).","error":"TypeError: bunchee is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"bunchee"}