Registry / devops / rollup-plugin-preserve-shebangs

rollup-plugin-preserve-shebangs

JSON →
library0.2.0jsnpmunverified

Rollup plugin that preserves shebang lines (e.g., #!/usr/bin/env node) in bundled output files. Version 0.2.0, last released in 2023. It solves Rollup's inability to parse shebangs by stripping them before compilation and re-adding them to the final output. A lightweight alternative to manual workarounds or community forks. Supports Rollup 2+ and 3+ via peer dependency. Ships TypeScript definitions. No active development, but stable for its niche use case.

npm install rollup-plugin-preserve-shebangs
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-PRES
R
rollup-plugin-preserve-shebangs
devopsjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

preserveShebangs
import { preserveShebangs } from 'rollup-plugin-preserve-shebangs'
const { default: preserveShebangs } = require('rollup-plugin-preserve-shebangs')
Named export. ESM or CJS both work.
default import
import preserveShebangs from 'rollup-plugin-preserve-shebangs'
const preserveShebangs = require('rollup-plugin-preserve-shebangs')
Default export is also available for convenience.
type
import type { RollupPreserveShebangsOptions } from 'rollup-plugin-preserve-shebangs'
TypeScript types are included, but not exported explicitly. Use the plugin's function type inference.

Example Rollup config using preserveShebangs plugin to handle shebang in CLI entry point.

// rollup.config.js import { preserveShebangs } from 'rollup-plugin-preserve-shebangs'; export default { input: 'src/cli.js', output: { file: 'dist/cli.js', format: 'cjs' }, plugins: [preserveShebangs()] };
Debug
Known issues
gotchaPlugin must be the first plugin in the plugins array to strip shebang before other transformations.
fix
Move preserveShebangs() to the beginning of the plugins list.
affects: >=0.1.0
gotchaOnly works with shebang as the very first line of the file (byte order mark (BOM) before shebang may cause issues).
fix
Remove BOM from input files or use a BOM-stripping plugin first.
affects: >=0.1.0
deprecatedPlugin is unmaintained since 2023; no updates for Rollup 4 compatibility verified.
fix
Test with Rollup 4; if broken, consider manually handling shebang via banner option or custom plugin.
affects: <=0.2.0
Errors
Common errors & fixes
Error: Unexpected character '#'
Rollup cannot parse shebang line as JavaScript.
fix
Add preserveShebangs() plugin to rollup config.
Module not found: Error: Can't resolve 'rollup-plugin-preserve-shebangs'
Plugin not installed or incorrect import path.
fix
Run npm install rollup-plugin-preserve-shebangs --save-dev and check import statement.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
rolluprequiredpeer dependency required for plugin API
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-preserve-shebangs — npm install rollup-plugin-preserve-shebangs · libregistry