Skip to content

fix: keep the library entry free of a shebang - #1080

Closed
blueDaydreaming725 wants to merge 1 commit into
motdotla:masterfrom
blueDaydreaming725:fix/library-entry-shebang
Closed

blueDaydreaming725 wants to merge 1 commit into
motdotla:masterfrom
blueDaydreaming725:fix/library-entry-shebang

Conversation

@blueDaydreaming725

Copy link
Copy Markdown

Fixes #1079

The library entry is also the CLI executable, so its bundle starts with a shebang. With Vite and nodePolyfills({ include: ["buffer"], globals: { Buffer: true } }), injected imports move that line into the middle of the served module. The browser throws a SyntaxError before parse() can run.

Build the existing library and CLI entry files separately, point the npm command at dist/cli.cjs, and keep the executable header and permissions there. The library entry no longer has a shebang. This reuses the existing CLI implementation while preserving the library exports, config preload paths and direct node dist/index.cjs behaviour. CLI tests now resolve the executable from package.json so they exercise the installed entry.

The new regression compiles the built library inside a CommonJS wrapper and calls parse(): the original bundle fails with a SyntaxError and the repaired bundle passes. npm test passes (build, Standard, TypeScript declarations and TAP; the Windows-only test is skipped on macOS). The issue's Vite 8.3.5 / polyfills 0.28.0 reproduction was also checked in real headless Chrome against current upstream and the fix: SyntaxError before, both parsed values and no browser errors after. The generated tarball was also installed in a temporary project: the npm executable, environment loading, child exit status, CJS/ESM imports and config preload paths all work.

Validated on macOS with Node 24. Native Windows/Linux and older Node versions were not run locally.

@motdotla

motdotla commented Nov 9, 2026

Copy link
Copy Markdown
Owner

@blueDaydreaming725 thank you so much for this PR. I'm sorry I didn't see it first, but just patched the issue here: #1082. It additionally bundles the cli outside the library.

@motdotla motdotla closed this Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using as a browser lib with vite-plugin-node-polyfills broken after v18?

2 participants