{"id":14814,"library":"pkgroll","title":"pkgroll: Zero-Config Rollup Bundler","description":"pkgroll is a robust JavaScript package bundler built on Rollup, designed for zero-configuration builds by leveraging existing `package.json` fields like `main`, `module`, `types`, and `exports`. It streamlines the process of transforming TypeScript/ESM source code into various output formats, including ESM, CommonJS, and TypeScript declaration files (`.d.ts`). Currently stable at version 2.27.0, pkgroll maintains a frequent release cadence, with multiple bug fixes and minor feature additions observed monthly. Its key differentiators include automatic dependency externalization, built-in minification, comprehensive TypeScript support with `.d.ts` bundling, watch mode for development, and intelligent CLI output features such as hashbang insertion for executables. It simplifies package publishing by reducing the need for extensive build configurations.","status":"active","version":"2.27.0","language":"javascript","source_language":"en","source_url":"https://github.com/privatenumber/pkgroll","tags":["javascript","zero config","rollup","package.json","exports","esm","cjs","commonjs","typescript"],"install":[{"cmd":"npm install pkgroll","lang":"bash","label":"npm"},{"cmd":"yarn add pkgroll","lang":"bash","label":"yarn"},{"cmd":"pnpm add pkgroll","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency required for TypeScript compilation and declaration file generation.","package":"typescript","optional":false}],"imports":[],"quickstart":{"code":"{\n    \"name\": \"my-package\",\n    \"version\": \"1.0.0\",\n    \"type\": \"module\",\n    \"main\": \"./dist/index.cjs\",\n    \"module\": \"./dist/index.mjs\",\n    \"types\": \"./dist/index.d.ts\",\n    \"exports\": {\n        \".\": {\n            \"require\": {\n                \"types\": \"./dist/index.d.cts\",\n                \"default\": \"./dist/index.cjs\"\n            },\n            \"import\": {\n                \"types\": \"./dist/index.d.mts\",\n                \"default\": \"./dist/index.mjs\"\n            }\n        },\n        \"./foo\": {\n            \"import\": \"./dist/foo.mjs\",\n            \"require\": \"./dist/foo.cjs\"\n        }\n    },\n    \"scripts\": {\n        \"build\": \"pkgroll\"\n    },\n    \"devDependencies\": {\n        \"pkgroll\": \"^2.0.0\",\n        \"typescript\": \"^5.0.0\"\n    }\n}\n// To run the build:\nnpm install\nnpm run build","lang":"json","description":"This quickstart demonstrates how to configure `package.json` for `pkgroll` to define entry points and output formats, then run the build."},"warnings":[{"fix":"Install a compatible TypeScript version: `npm install --save-dev typescript@\"^5.0\"` or `npm install --save-dev typescript@\"^4.1\"` as required by your pkgroll version.","message":"pkgroll has a peer dependency on TypeScript. Ensure you install a compatible version (e.g., `^4.1` or `^5.0`). While v2.27.0 supports TypeScript 6, older versions of pkgroll or incompatible TypeScript installations can lead to build failures.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Place source files corresponding to `dist` outputs in a `src` directory (e.g., `src/index.ts` for `dist/index.cjs`), or use `pkgroll --srcdist 'my-src:my-dist'` to define custom mappings.","message":"pkgroll automatically maps output paths defined in `package.json` (e.g., `./dist/index.cjs`) to source files (e.g., `./src/index.ts`). Ensure your source file structure aligns with these inferred mappings, or use the `--srcdist` flag for custom source/distribution directory mappings.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Always specify a file extension in wildcard export patterns: `\"./utils/*\": \"./dist/utils/*.mjs\"`.","message":"When using wildcard patterns in `package.json#exports` (e.g., `./utils/*`), it is critical to include a file extension in the pattern (e.g., `./dist/utils/*.mjs`). Failing to do so will result in an error as pkgroll requires explicit file extensions for wildcard resolution.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Consult Node.js documentation on `package.json#exports` and ensure all required conditions (`import`, `require`, `types`) are correctly specified for each entry point to support all target environments.","message":"pkgroll relies heavily on `package.json` `exports` field for defining entry points and output formats. Incorrect or incomplete configuration of `exports`, especially regarding `import` and `require` conditions, can lead to incorrect bundling or runtime issues in consumers.","severity":"gotcha","affected_versions":">=2.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: `npm install --save-dev typescript` or `pnpm add -D typescript`.","cause":"The `typescript` peer dependency is not installed in the project.","error":"Error: Cannot find module 'typescript'"},{"fix":"Modify the `exports` entry to include a file extension, for example: `\"./utils/*\": \"./dist/utils/*.mjs\"`.","cause":"A wildcard pattern in `package.json#exports` is missing a file extension.","error":"Error: Wildcard pattern must include a file extension (e.g. `*.mjs`)"},{"fix":"Update Node.js to a version that fully supports `package.json#exports` (Node.js 14.13+ for most features, 16+ for full stable support). Review `package.json` for syntax errors.","cause":"Using advanced `package.json#exports` features (like nested conditions or specific `types` exports) with an older Node.js version that doesn't support them, or a malformed `package.json` structure.","error":"Error: Unknown export field 'exports.require.types'"}],"ecosystem":"npm"}