chore: normalize Node builtin imports to the node: prefix#307
chore: normalize Node builtin imports to the node: prefix#307jaredglaser wants to merge 1 commit into
Conversation
Add the node: prefix to every bare Node builtin import specifier across
26 files (crypto, fs, fs/promises, path, stream, readline, child_process,
url) plus the dynamic await import('crypto'). Specifier strings only, no
logic changes. Matches the node: prefix already used elsewhere and Bun's
recommended form for builtins.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FxgTwf24W7eq49v7fV7CdD
📝 WalkthroughWalkthroughAll Node.js built-in module imports across 26 source and test files are updated from bare specifiers ( Changesnode: specifier migration
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
What
Adds the
node:prefix to every bare Node builtin import specifier across 26 files (crypto,fs,fs/promises,path,stream,readline,child_process,url), plus the dynamicawait import('crypto')ingit-tokens.functions.tsx. Specifier strings only, no logic changes (43 insertions / 43 deletions, fully symmetric).Why
This started from the question "should we replace
node:APIs with Bun alternatives?" The conclusion was no: Bun implementsnode:*natively and recommends the prefixed form, and swappingsrc/toBun.*APIs would couple shared code to Bun for negligible benefit. The genuinely useful cleanup was the opposite direction: most of the codebase already uses thenode:prefix, but ~26 files used bare specifiers. This change makes them consistent.Background: the "run dev under Bun" idea was tried and dropped
A second change was scoped to make
bun devrun under Bun (viabun --bun vite) so dev matches the prod/worker runtime. During validation it was found to break the dev server: it boots (VITE ready) but returns HTTP 500 on every request because Nitro's Vite dev entry wires websocket support throughcrossws, whose Node adapter rejects the Bun runtime. That isn't a quick/safe fix (disabling websockets would break real features), so the dev-runtime change was reverted and is not part of this PR. Dev stays on Node, prod stays on Bun, andsrc/remains runtime-agnostic, which is exactly why thenode:builtins (notBun.*) are the right call.How to reproduce the dev-under-Bun failure locally
This PR does NOT contain these changes. Apply them yourself to observe the issue:
In
package.json, change thedevscript:The
--bunflag overrides thevitebinary's#!/usr/bin/env nodeshebang and forces the Bun runtime. Without it,bun devstill runs Vite under Node.Make sure deps are installed (
bun run setup), then start dev:It boots fine:
Hit any route and watch it fail:
Returns
HTTP/1.1 500, and the dev server stdout prints:Revert the
package.jsonchange to get a working dev server again.Root cause:
vite.config.tsenablesnitro({ ..., features: { websocket: true } }). Nitro's Vite dev entry instantiates thecrosswsNode adapter for websocket support, and that adapter throws when it detects a non-Node runtime (Bun). The web server only runs under Bun in production (Dockerfile:bun .output/server/index.mjs), where this dev-only Nitro path isn't used, so prod is unaffected.Possible paths to actually enable it (out of scope here, would need investigation): a Nitro Bun/dev preset or a crossws Bun adapter, or gating
features.websocketper-environment if dev websockets aren't needed.Verification
bun run typecheck:allpasses.bun run test:all: identical results before and after (2479 pass / 396 fail), and identical to the base commit. The pre-existing failures are unrelated environment/mock-isolation issues, not introduced here.🤖 Generated with Claude Code