Bun "TypeError: X is not a function" (Node API gap) in CI
A dependency called a Node.js API that Bun does not fully implement, so the method is undefined and Bun throws "TypeError: X is not a function". This surfaces on Bun even when the code runs on Node.
What this error means
Under Bun a step throws "TypeError: someNodeApi is not a function" or "X.method is not a function", pointing inside a dependency that assumes a Node built-in.
TypeError: v8.serialize is not a function
at /home/runner/work/app/node_modules/some-lib/index.js:12:20Common causes
A Node API not yet implemented in Bun
The dependency relies on a Node built-in method Bun has not implemented, so it is undefined at runtime.
A behavioral difference in a partially-supported API
Bun implements the module but not this specific function or signature, so the call fails where Node would succeed.
How to fix it
Confirm the gap and pick an alternative
- Identify the exact Node API from the stack trace.
- Use a dependency version or code path that avoids the unsupported call.
- If the code is yours, switch to a Bun-supported API or a Web API equivalent.
# reproduce under Bun to confirm the missing API
bun run ./scripts/repro.tsRun that job on Node while the gap remains
If a dependency needs an unimplemented Node API, run that specific job on Node until Bun closes the gap.
- uses: actions/setup-node@v4
with:
node-version: '20'
- run: node ./scripts/task.jsHow to prevent it
- Test dependencies under Bun before relying on them in CI.
- Track Bun Node-compatibility notes for APIs you depend on.
- Isolate jobs that need unsupported Node APIs onto Node runners.