Is it possible to remove all require() calls in a bundled script?
- Dominant language
- Go
- Stars
- 40.1k
- Forks
- 1.3k
- PR merge metrics
- No merged PRs in 30d
Description
I'm experimenting with bundling `npm` to a standalone executable using the procedures outlined by Deno, Bun, and Node.js.
One observation of the Node.js https://nodejs.org/api/single-executable-applications.html#requireid-in-the-injected-main-script-is-not-file-based and Bun https://bun.sh/docs/bundler#executables implementations is that when the source entry points are removed from the file system the repective resulting executable throws module not found error.
For whatever reason, Node.js and Bun implementations expect the source entry point files to still be present of the file system for the executable to work.
So my idea is to bundle all dependencies into a single script that effectively refers to itself for `require()` calls, and does not try to use `require()` at all.
Is this possible using `esbuild`?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the issue's references to Node.js single-executable applications and the Bun bundler executable documentation, then investigate how esbuild handles require() calls in bundled output. Done means establishing whether a standalone bundle can avoid filesystem-based entry points and require() calls, and documenting the supported approach or limitation.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- bun, deno, javascript, node.js
- Domain
- build-system, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100