mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #293] [CLOSED] fix: stub node:async_hooks in client builds to prevent Rollup errors #453
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#453
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/293
Author: @Divkix
Created: 3/6/2026
Status: ❌ Closed
Base:
main← Head:fix/async-hooks-browser-stub📝 Commits (4)
0108ac0fix: stub node:async_hooks in client builds to prevent Rollup errors2454868fix: address PR #293 review — extensionless shim path + testsab57ce5Merge branch 'cloudflare:main' into fix/async-hooks-browser-stubf07748cfix(tests): use dynamic import instead of require in async_hooks tests📊 Changes
3 files changed (+101 additions, -3 deletions)
View changed files
📝
packages/vinext/src/index.ts(+12 -3)➕
packages/vinext/src/shims/async-hooks-browser.ts(+17 -0)📝
tests/shims.test.ts(+72 -0)📄 Description
Summary
AsyncLocalStoragefromnode:async_hooks. When resolved into the client (browser) build, Vite externalizesnode:async_hooksto__vite-browser-external— an empty stub with no named exports. This causes Rollup named-export failures.node:async_hooksnatively vianodejs_compat. Only the client environment needs a stub.AsyncLocalStoragestub atpackages/vinext/src/shims/async-hooks-browser.tswith no-op methods (run()passes through,getStore()returnsundefined— matching existing_als.getStore() ?? _fallbackStatepatterns in shims).resolveIdfilter to matchnode:async_hooksand redirect to the stub only whenthis.environment.name === "client".Reproduction
.vite/)bun run buildon an App Router project with shims that importAsyncLocalStorage"AsyncLocalStorage" is not exported by "__vite-browser-external"Fix
Two changes:
packages/vinext/src/shims/async-hooks-browser.ts— browser-safe no-opAsyncLocalStorageclasspackages/vinext/src/index.ts— extendedresolveIdhook to redirectnode:async_hooks→ stub in client environment onlyTest plan
run()correctly passes through the callback return valuenode:async_hooks— no behavioral changebiome checkpasses on all changed files🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.
asparameter in router.push/replace #582