Skip to content

vercel: building with Bun publishes bun1.x even when package.json sets engines.node #4767

Closed

Description

@everton-dgn

Environment

  • nitro 3.0.260903-beta (same code on main at cef5305)
  • preset vercel
  • Bun 1.4.2 running the build with --bun, Node.js 24.21.0 installed

Reproduction

Save these two files in an empty directory, install the dependencies, then run the commands below.

{
  "type": "module",
  "engines": { "node": ">=24.20.0 <25" },
  "scripts": { "build": "nitro build --preset vercel" },
  "devDependencies": { "nitro": "3.0.260903-beta" }
}
export default () => "ok";
bun install

bun --bun run build
jq .runtime .vercel/output/functions/__server.func/.vc-config.json
# "bun1.x"

npm run build
jq .runtime .vercel/output/functions/__server.func/.vc-config.json
# "nodejs24.x"

Describe the bug

resolveVercelRuntime in src/presets/vercel/utils.ts takes vercel.functions.runtime if set, then picks bun1.x when vercel.json has bunVersion or when "Bun" in globalThis, and otherwise uses the Node.js major of the build process. package.json is never read.

So a Vite app built with bun --bun vite build (the setup in #3806) gets a Bun function plus the bun export condition, even though engines.node says Node 24. The only way out today is to hardcode vercel.functions.runtime: "nodejs24.x". The "Bun runtime" section of docs/2.deploy/20.providers/vercel.md mentions the explicit runtime and bunVersion, but not that building with Bun switches the function to Bun.

Vercel resolves this the other way around. Since vercel/vercel#16685, getNodeVersion in @vercel/build-utils (packages/build-utils/src/fs/run-user-scripts.ts) checks engines.node and engines.bun first (with both set, Bun only when vercel.json has bunVersion), then bunVersion, and defaults to Node. Their docs say engines.node overrides the project setting and that a range like >=22.0.0 maps to 24.x: https://vercel.com/docs/functions/runtimes/node-js/node-js-versions

That resolution doesn't apply to Nitro output: with the Build Output API the function runtime is whatever .vc-config.json says, which is also what #4628 ran into with engines.node: "^24".

What I'd propose, inside the vercel preset only:

  1. vercel.functions.runtime
  2. engines in package.json: engines.node picks the newest entry of SUPPORTED_NODE_VERSIONS whose N.x intersects the range, engines.bun picks bun1.x, and with both set Bun wins only if vercel.json has bunVersion
  3. bunVersion in vercel.json
  4. the runtime running the build, as today

Steps 2 and 3 copy Vercel's precedence; 1 and 4 are what Nitro already does. Range matching would use semver intersects, the same check Vercel uses, so >=24.20.0 <25 gives nodejs24.x and >=20 gives nodejs24.x. That avoids the parseInt problem raised in #2794. semver is already a devDependency and would be loaded with import() only when engines.node is set (about 17 kB, 5 kB gzip).

Behavior changes to agree on first:

  • A project that builds with Bun and also declares engines.node moves from bun1.x to Node. That is the fix, but it changes output for anyone who relied on it. Is a warning wanted in that case, or is the Using nodejs24.x runtime. log enough?
  • engines.node plus bunVersion (without engines.bun) picks Node with a warning, matching Vercel. Today it picks Bun.
  • Open ranges move to the newest version. engines.node: ">=20" built on Node 22 publishes nodejs22.x today and would publish nodejs24.x. On Vercel's git integration nothing changes, since the build container already runs the newest version allowed by engines.node. It does change vercel deploy --prebuilt from a machine on Node 22: native modules built for Node 22 would run on 24, which is the crash from presets(vercel): add support for node@24 (v2) #4628 in the other direction. An alternative that keeps the alignment feat(vercel): auto-detect runtime version #879 was after: when not building with Bun, use the build's Node major if it is supported and satisfies engines.node, otherwise the newest match. Which one do you prefer?
  • If engines.node matches no supported version (18.x, >=26, lts/*), Nitro would warn and use the build's Node major, clamped as today. Vercel fails the build there. Under Bun this means Node instead of today's bun1.x, since engines.node asks for Node.
  • Node 20 would leave SUPPORTED_NODE_VERSIONS, the same way refactor(aws-amplify, azure, vercel): update node to 20, 22 #3572 dropped 18 after its Vercel cutoff. Vercel discontinued 20 on 2026-10-01 and the page linked above the list only shows 22.x and 24.x. Otherwise engines.node: "20.x" would start emitting nodejs20.x. A build running on Node 20 would map to nodejs22.x. This one can be a separate PR if you prefer.

Related: #879 added the build process detection, #3678 added Bun support, #2716 and #2794 discuss reading engines.node across presets, #2819 asked for Vercel's engines rules and was closed with the clamp only. The change stays in the vercel preset, following the per-provider approach suggested in #2716.

I opened a PR with this change, unit tests and a docs update, so the details are easy to review. I'm happy to adjust it to whichever option you prefer above.

Additional context

Workaround in the meantime:

export default defineConfig({
  vercel: { functions: { runtime: "nodejs24.x" } },
});

Logs

# bun --bun run build
[nitro:vercel] ℹ Using bun1.x runtime.

# npm run build
[nitro:vercel] ℹ Using nodejs24.x runtime.

Activity

  1. added
    enhancement
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementpreset:bunpreset:vercel

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions