Skip to content

fix(wrangler): bundle workerd-native modules missing from host Node.js - #17386

Merged
NuroDev merged 3 commits into
mainfrom
NuroDev/packages-pr-ci-test-8e0cb8
Dec 4, 2026
Merged

NuroDev merged 3 commits into
mainfrom
NuroDev/packages-pr-ci-test-8e0cb8

Conversation

@NuroDev

@NuroDev NuroDev commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Fixes the Tests (Node 26) failure on the Version Packages PR (#17371).

Node.js 26 removed _stream_wrap from its built-in modules. When nodejs_compat is enabled with a compat date on or after 2026-01-29, @cloudflare/unenv-preset treats _stream_wrap as a workerd-native module: it aliases the module to itself and marks it external. handleUnenvAliasedPackages resolved every alias with require.resolve() and silently dropped the ones that threw. On Node 26 the _stream_wrap alias was dropped, and esbuild then failed with Could not resolve "node:_stream_wrap".

External aliases for Node.js built-ins (node:*, plus the bare names in nonPrefixedNodeModules) are now marked external directly, without resolving them against the Node.js version running Wrangler. Bare names that only exist with the node: prefix, like sqlite, 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-versions label), so normal PRs did not catch it.


  • Tests
    • Tests included/updated
    • Automated tests not possible - manual testing has been completed as follows:
    • Additional testing not necessary because:
  • Public documentation
    • Cloudflare docs PR(s):
    • Documentation not necessary because: bug fix with no user-facing configuration or API changes

The new unit test in deploy/build.test.ts reproduces 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. The unenv-preset e2e suite passes locally on Node 26.14 (2378 passed, 142 skipped).

🤖 Generated with Claude Code


Devin Review

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-bot

changeset-bot Bot commented Dec 4, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8992bee

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
wrangler Patch

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

@github-project-automation github-project-automation Bot moved this to Untriaged in workers-sdk Dec 4, 2026
@NuroDev NuroDev self-assigned this Dec 4, 2026
@workers-devprod
workers-devprod requested review from a team and petebacondarwin and removed request for a team December 4, 2026 17:35
@workers-devprod

workers-devprod commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Codeowners approval required for this PR:

  • ✅ @cloudflare/wrangler
Show detailed file reviewers

@clanky-the-clanker clanky-the-clanker Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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 sqlite still go through require.resolve.
  • Only aliases kept as native built-ins are returned as external, so an npm sqlite package that resolves is bundled instead of being imported by an absolute path.
  • The new sqlite fixture test runs on every Node version.
  • The _stream_wrap test 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

@pkg-pr-new

pkg-pr-new Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
@cloudflare/autoconfig

npm i https://pkg.pr.new/@cloudflare/autoconfig@17386

@cloudflare/build-output-utils

npm i https://pkg.pr.new/@cloudflare/build-output-utils@17386

@cloudflare/cli-shared-helpers

npm i https://pkg.pr.new/@cloudflare/cli-shared-helpers@17386

@cloudflare/codemods

npm i https://pkg.pr.new/@cloudflare/codemods@17386

@cloudflare/config

npm i https://pkg.pr.new/@cloudflare/config@17386

@cloudflare/containers-shared

npm i https://pkg.pr.new/@cloudflare/containers-shared@17386

create-cloudflare

npm i https://pkg.pr.new/create-cloudflare@17386

@cloudflare/deploy-helpers

npm i https://pkg.pr.new/@cloudflare/deploy-helpers@17386

@cloudflare/kv-asset-handler

npm i https://pkg.pr.new/@cloudflare/kv-asset-handler@17386

miniflare

npm i https://pkg.pr.new/miniflare@17386

@cloudflare/pages-functions

npm i https://pkg.pr.new/@cloudflare/pages-functions@17386

@cloudflare/pages-shared

npm i https://pkg.pr.new/@cloudflare/pages-shared@17386

@cloudflare/runtime-types

npm i https://pkg.pr.new/@cloudflare/runtime-types@17386

@cloudflare/test-server

npm i https://pkg.pr.new/@cloudflare/test-server@17386

@cloudflare/unenv-preset

npm i https://pkg.pr.new/@cloudflare/unenv-preset@17386

@cloudflare/vite-plugin

npm i https://pkg.pr.new/@cloudflare/vite-plugin@17386

@cloudflare/vitest-plugin

npm i https://pkg.pr.new/@cloudflare/vitest-plugin@17386

@cloudflare/workers-auth

npm i https://pkg.pr.new/@cloudflare/workers-auth@17386

@cloudflare/workers-editor-shared

npm i https://pkg.pr.new/@cloudflare/workers-editor-shared@17386

@cloudflare/workers-utils

npm i https://pkg.pr.new/@cloudflare/workers-utils@17386

wrangler

npm i https://pkg.pr.new/wrangler@17386

commit: 8992bee

devin-ai-integration[bot]

This comment was marked as resolved.

@ask-bonk

ask-bonk Bot commented Dec 4, 2026

Copy link
Copy Markdown
Contributor

LGTM

github run

@NuroDev

NuroDev commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

clanky review

@NuroDev NuroDev added the ci:test-all-node-versions Run the tests on all Node versions for this PR label Dec 4, 2026
…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>
devin-ai-integration[bot]

This comment was marked as resolved.

@workers-devprod workers-devprod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@NuroDev
NuroDev merged commit 4e2992a into main Dec 4, 2026
84 checks passed
@NuroDev
NuroDev deleted the NuroDev/packages-pr-ci-test-8e0cb8 branch December 4, 2026 18:05
@github-project-automation github-project-automation Bot moved this from Untriaged to Done in workers-sdk Dec 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci:test-all-node-versions Run the tests on all Node versions for this PR

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants