Repository navigation
fix(wrangler): bundle workerd-native modules missing from host Node.js - #17386
Conversation
Node.js 26 dropped the `_stream_wrap` built-in, so `require.resolve()` threw for the unenv alias, the alias was silently dropped, and esbuild failed with `Could not resolve "node:_stream_wrap"`. Mark external aliases as external directly instead of resolving them against the Node.js version running Wrangler. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
🦋 Changeset detectedLatest commit: 8992bee The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers |
There was a problem hiding this comment.
✅ Approved — No issues found: native built-in aliases are kept as external without resolving them on the host Node.js, and prefix-only bare names like sqlite bundle an installed npm package.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
I found no security concerns in this change.
📋 Code Quality: ✅ LGTM
handleUnenvAliasedPackages now keeps node:* aliases and names in nonPrefixedNodeModules as raw strings. It marks them external without calling require.resolve, which fixes _stream_wrap on Node 26.
- Bare prefix-only names such as
sqlitestill go throughrequire.resolve. - Only aliases kept as native built-ins are returned as
external, so an npmsqlitepackage that resolves is bundled instead of being imported by an absolute path. - The new
sqlitefixture test runs on every Node version. - The
_stream_wraptest can only tell the old and new behaviour apart on Node 26, which the Node 26 CI job runs.
📝 Documentation: ✅ LGTM
The changeset is a patch bump, has no type prefix in its title, and describes the outcome for users.
Reviewed commit: 8992bee2
@cloudflare/autoconfig
@cloudflare/build-output-utils
@cloudflare/cli-shared-helpers
@cloudflare/codemods
@cloudflare/config
@cloudflare/containers-shared
create-cloudflare
@cloudflare/deploy-helpers
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-functions
@cloudflare/pages-shared
@cloudflare/runtime-types
@cloudflare/test-server
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-plugin
@cloudflare/workers-auth
@cloudflare/workers-editor-shared
@cloudflare/workers-utils
wrangler
commit: |
|
LGTM |
|
clanky review |
…ules `sqlite` only exists as `node:sqlite`, but the preset also marks the bare `sqlite` alias as external. Only skip host resolution for names that are Node.js built-ins, so an installed `sqlite` npm package is still bundled. Also reword the changeset around the user-facing outcome. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
workers-devprod
left a comment
There was a problem hiding this comment.
Codeowners reviews satisfied
If an npm package named after a prefix-only module (e.g. `sqlite`) can be resolved from Wrangler's own location, `require.resolve()` succeeds and the alias was still marked external, leaving an import of an absolute host path in the bundle. Mark only the aliases kept as native built-ins as external, so resolved packages are bundled. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Fixes the
Tests (Node 26)failure on the Version Packages PR (#17371).Node.js 26 removed
_stream_wrapfrom its built-in modules. Whennodejs_compatis enabled with a compat date on or after 2026-01-29,@cloudflare/unenv-presettreats_stream_wrapas a workerd-native module: it aliases the module to itself and marks it external.handleUnenvAliasedPackagesresolved every alias withrequire.resolve()and silently dropped the ones that threw. On Node 26 the_stream_wrapalias was dropped, and esbuild then failed withCould not resolve "node:_stream_wrap".External aliases for Node.js built-ins (
node:*, plus the bare names innonPrefixedNodeModules) are now marked external directly, without resolving them against the Node.js version running Wrangler. Bare names that only exist with thenode:prefix, likesqlite, still go through the old resolution path, so an installed npm package with that name is bundled. For modules the host Node.js still provides, the bundled output does not change.This started showing up after #17336 swapped the CI matrix from Node 25 to Node 26. That job only runs on Version Packages PRs (or with the
ci:test-all-node-versionslabel), so normal PRs did not catch it.The new unit test in
deploy/build.test.tsreproduces the failure on Node 26 and passes with this fix. On Node 24 it passes either way, but the Node 26 CI job runs it. Theunenv-presete2e suite passes locally on Node 26.14 (2378 passed, 142 skipped).🤖 Generated with Claude Code