{"id":21929,"library":"rollup-plugin-banner2","title":"rollup-plugin-banner2","description":"Rollup plugin to prepend a banner (e.g., license, metadata) before bundled JavaScript code, surviving minification where Rollup's built-in output.banner is stripped by plugins like rollup-plugin-uglify. Version 1.3.1 (stable; maintained as of 2024). Key differentiators from rollup-plugin-banner (unmaintained): supports sourcemaps, per-chunk banners via ChunkInfo, custom formatters (docBlock, docBlockAndGap), and async resolveBanner. Drawbacks vs alternatives: no file path loading, no package.json template injection, no automatic JS comment wrapping. Requires Node >=12.13 and Rollup.","status":"active","version":"1.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/stropho/rollup-plugin-banner2","tags":["javascript"],"install":[{"cmd":"npm install rollup-plugin-banner2","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-banner2","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-banner2","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin is a Rollup plugin and requires Rollup at runtime.","package":"rollup","optional":true}],"imports":[{"note":"Package is ESM-only; CJS require will fail with ERR_REQUIRE_ESM in Node >=12.","wrong":"const banner2 = require('rollup-plugin-banner2')","symbol":"banner2","correct":"import banner2 from 'rollup-plugin-banner2'"},{"note":"resolveBanner must be a function, not a string literal.","wrong":"export default { plugins: [banner2('/* my banner */')] }","symbol":"banner2","correct":"export default { plugins: [banner2(() => '/* my banner */')] }"},{"note":"Type-only import; runtime import will throw TypeError.","wrong":"import { BannerFunction } from 'rollup-plugin-banner2'","symbol":"BannerFunction","correct":"import type { BannerFunction } from 'rollup-plugin-banner2'"}],"quickstart":{"code":"import banner2 from 'rollup-plugin-banner2';\n\nexport default {\n  input: 'src/index.js',\n  output: { dir: 'dist', format: 'es' },\n  plugins: [\n    banner2(\n      (chunk) => `/**\n * Bundle: ${chunk.fileName}\n */\n`,\n      { formatter: 'docBlock' }\n    )\n  ]\n};","lang":"typescript","description":"Basic Rollup config using banner2 with per-chunk banners and docBlock formatter."},"warnings":[{"fix":"Use import syntax. Update Node to >=12.13. If legacy CJS required, use dynamic import() or downgrade to rollup-plugin-banner (CJS).","message":"Package is ESM-only since v1.0. Node <12 incompatible; CJS require() fails.","severity":"breaking","affected_versions":">=1.0"},{"fix":"Use resolveBanner function to implement custom formatting.","message":"The 'formatter' option only supports 'docBlock' and 'docBlockAndGap'; custom formatters were removed in a prior version.","severity":"deprecated","affected_versions":">=1.2"},{"fix":"Ensure function always returns something (string, Buffer, etc.) or handle falsey explicitly.","message":"resolveBanner must return a string, stringifiable object, or falsey. Returning undefined or null results in empty banner.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"If banner is stripped by minifier, try disabling sourcemaps (sourcemap: false) or use a dedicated banner plugin designed for minifiers.","message":"When sourcemaps are enabled (default), banner content is added to sourcemaps; minifiers may still strip banner if not sourcemap-aware.","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use import statement instead of require().","cause":"Using CommonJS require() with ESM-only package.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/rollup-plugin-banner2/index.js not supported."},{"fix":"Use import banner2 from 'rollup-plugin-banner2' (correct) or const banner2 = (await import('rollup-plugin-banner2')).default.","cause":"Importing with incorrect syntax or using default import for a named export.","error":"TypeError: banner2 is not a function"},{"fix":"Change sourceMap to sourcemap in options object.","cause":"Using incorrect camelCase option name.","error":"Error: The \"sourceMap\" option is deprecated; use \"sourcemap\" (all lowercase)."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}