{"id":15562,"library":"bundlib","title":"Bundlib","description":"Bundlib is an automatic library bundler built on top of Rollup.js, designed to streamline the process of packaging JavaScript and TypeScript libraries. The current stable version is 0.21.9, with active development indicated by frequent patch releases (0.21.9, 0.21.8, 0.21.7, etc.) that introduce new features like parallel builds and improved CLI commands, alongside bug fixes. It aims to simplify Rollup configuration for common library bundling scenarios, offering both automatic configuration derived from `package.json` and advanced programmatic or file-based configuration via `defineConfig`. A key differentiator is its focus on opinionated defaults to reduce setup complexity, while still allowing fine-grained control for various build types (ESM, CJS, UMD, types). Users should note that while powerful, the project is explicitly stated to be \"under development,\" suggesting potential for evolving APIs or unresolved edge cases. It ships with TypeScript types and requires Node.js >=18.","status":"active","version":"0.21.9","language":"javascript","source_language":"en","source_url":"https://github.com/manferlo81/bundlib","tags":["javascript","library","bundle","bundler","typescript","rollup"],"install":[{"cmd":"npm install bundlib","lang":"bash","label":"npm"},{"cmd":"yarn add bundlib","lang":"bash","label":"yarn"},{"cmd":"pnpm add bundlib","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Bundlib is powered by Rollup.js and uses it for the underlying bundling process. It's a fundamental dependency for Bundlib's operation.","package":"rollup","optional":false}],"imports":[{"note":"Primarily used in `bundlib.config.ts` or `bundlib.config.js` files for type-safe configuration. CommonJS `require` is incorrect in most modern Node.js environments as Bundlib targets ESM.","wrong":"const { defineConfig } = require('bundlib');","symbol":"defineConfig","correct":"import { defineConfig } from 'bundlib'"},{"note":"The main programmatic function for initiating a build. Bundlib is an ESM-first package, requiring named imports even for the main function.","wrong":"const bundlib = require('bundlib').bundlib;","symbol":"bundlib","correct":"import { bundlib } from 'bundlib'"},{"note":"This is a TypeScript type definition, exclusively for type-checking. Using `type` import is crucial to prevent runtime errors or unnecessary bundling in modern TypeScript.","wrong":"import { BundlibConfig } from 'bundlib'","symbol":"BundlibConfig","correct":"import type { BundlibConfig } from 'bundlib'"}],"quickstart":{"code":"/* bundlib.config.ts */\nimport { defineConfig } from 'bundlib';\n\nexport default defineConfig({\n  input: 'src/index.ts', // Your main entry point\n  output: [\n    { format: 'es', file: 'dist/index.mjs', sourcemap: true },\n    { format: 'cjs', file: 'dist/index.cjs', sourcemap: true },\n    { format: 'umd', file: 'dist/index.umd.js', name: 'MyLibrary', sourcemap: true }\n  ],\n  // Optional: Define external dependencies to prevent bundling them\n  external: ['lodash'],\n  // Optional: Configure TypeScript for type declarations\n  project: 'tsconfig.json',\n  // Optional: Enable minification for production builds\n  min: process.env.NODE_ENV === 'production'\n});\n\n/* package.json */\n// Add a script to your package.json\n// \"scripts\": {\n//   \"build\": \"bundlib build\",\n//   \"watch\": \"bundlib watch\"\n// }\n\n// To run the build:\n// npm install --save-dev bundlib rollup typescript\n// npm run build\n","lang":"typescript","description":"Demonstrates defining a multi-format library configuration using `defineConfig` in a `bundlib.config.ts` file, and shows how to invoke the build via the CLI in `package.json`."},"warnings":[{"fix":"Monitor official releases and changelogs closely for updates. Consider pinning to minor versions and thoroughly testing updates in a staging environment.","message":"Bundlib is explicitly stated to be \"under development\". This implies that APIs might still evolve, and users should be prepared for potential changes or edge cases as the project matures.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Upgrade your Node.js environment to version 18 or newer using tools like `nvm` or by installing a recent Node.js distribution.","message":"Bundlib requires Node.js version >=18. Running with older Node.js versions will result in execution errors.","severity":"breaking","affected_versions":">=0.21.0"},{"fix":"Refer to the updated documentation or run `bundlib --help` to understand the correct CLI syntax for `build` and `watch` commands. Ensure your `package.json` scripts are updated accordingly.","message":"CLI commands for `build` and `watch` were significantly refactored and introduced in version 0.21.5, potentially changing how users interact with the bundler from the command line.","severity":"breaking","affected_versions":">=0.21.5"},{"fix":"Always test new Bundlib versions thoroughly, especially if you rely on specific Rollup plugins or complex build configurations. Consult the Rollup plugin's changelogs for breaking changes when updating Bundlib.","message":"Upgrades to underlying Rollup plugins (e.g., `@rollup/plugin-commonjs` fix in v0.21.4) can introduce subtle breaking changes or require configuration adjustments, particularly for browser builds.","severity":"gotcha","affected_versions":">=0.21.4"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure you are using ESM `import` statements (e.g., `import { defineConfig } from 'bundlib';`). For TypeScript, verify `moduleResolution` in `tsconfig.json` supports modern ESM (e.g., `\"node16\"` or `\"bundler\"`).","cause":"Attempting to `require()` Bundlib in a CommonJS context when it's primarily an ESM package, or incorrect module resolution in a TypeScript project.","error":"Error: Cannot find module 'bundlib' or its corresponding type declarations."},{"fix":"Update your Node.js environment to version 18 or newer. Use `nvm install 18` and `nvm use 18` or similar version management tools.","cause":"Running Bundlib with an unsupported Node.js version as specified in its `engines` field.","error":"Error: Your current Node.js version is X. Bundlib requires Node.js >=18."},{"fix":"Ensure your `bundlib.config.ts` or `package.json` configuration explicitly defines the `input` option, pointing to your library's main source file (e.g., `input: 'src/index.ts'`).","cause":"The Rollup configuration generated by Bundlib lacks a specified entry point for bundling.","error":"Error: Missing \"input\" option"},{"fix":"Use named import: `import { defineConfig } from 'bundlib';`. If using CommonJS, ensure your setup correctly transpiles ESM or update to an ESM-compatible environment.","cause":"Incorrect import of `defineConfig` or attempting to access it as a property of a default import.","error":"TypeError: bundlib.defineConfig is not a function"}],"ecosystem":"npm"}