Skip to content
Latchkey

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.

Terminal
TypeError: v8.serialize is not a function
  at /home/runner/work/app/node_modules/some-lib/index.js:12:20

Common 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

  1. Identify the exact Node API from the stack trace.
  2. Use a dependency version or code path that avoids the unsupported call.
  3. If the code is yours, switch to a Bun-supported API or a Web API equivalent.
Terminal
# reproduce under Bun to confirm the missing API
bun run ./scripts/repro.ts

Run 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.

.github/workflows/ci.yml
- uses: actions/setup-node@v4
  with:
    node-version: '20'
- run: node ./scripts/task.js

How 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.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →