Fix Vite config-loader warnings and async_hooks browser stub in the CLI build - #4774
Merged
Conversation
Vite 8 warns that the build configs use features unsupported by the
upcoming `configLoader: 'native'` default: `__dirname`, extensionless
relative imports, and JSON imports without attributes. Node >=22 is
already required, so `import.meta.dirname` is available; JSON imports use
createRequire (as apps/ui already did) because the pinned wp-prettier
cannot parse import attributes and tsconfig targets es2022.
The same build also silently mis-resolved async_hooks. The CLI builds in
Vite's default `client` environment, so bundled Express dependencies
(on-finished, raw-body) had their `require('async_hooks')` rewritten to an
empty-object browser stub, leaving `AsyncResource` undefined and dropping
async context propagation in the `studio ui` server. Adding async_hooks to
the existing Node built-in externals resolves it through the per-chunk
createRequire shim while keeping express bundled, so the shipped CLI stays
self-contained.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Collaborator
📊 Performance Test ResultsComparing 4a6696f vs trunk app-size
site-editor
site-startup
Results are median values from multiple test runs. Legend: 🟢 Improvement (faster) | 🔴 Regression (slower) | ⚪ No change (<50ms diff) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related issues
How AI was used in this PR
Claude Code investigated the warnings, produced the changes, and verified them. All build output and the running server were inspected directly rather than trusting the absence of warnings.
Proposed Changes
Two problems surfaced by the same build output on
npm start.Vite 8 config-loader warnings. Every build and test run printed warnings that our configs use features unsupported by
configLoader: 'native', which becomes the default in a future Vite major:__dirname, extensionless relative imports, and JSON imports without attributes. Fixing them now keeps the noise out of everyone's terminal and means the eventual loader switch is a non-event rather than a broken build.Node >= 22 is already required, so
import.meta.dirnameis available. JSON imports usecreateRequire(the patternapps/uialready used) rather than thewith { type: 'json' }attribute the warning suggests — the pinnedwp-prettier@3.0.3cannot parse import attributes, andtsconfigtargetses2022, which doesn't permit them. Moving to the modern syntax is a separate change gated on those two upgrades.A real bug hiding behind one of those warnings. The
async_hooksexternalization message was not cosmetic. The CLI is a Node program, but Vite builds it in the defaultclientenvironment, so bundled Express dependencies were resolved with browser conditions.require('async_hooks')was rewritten to an empty-object stub:That left
asyncHooks.AsyncResourcepermanentlyundefined, soon-finishedandraw-bodysilently fell back to unwrapped callbacks — losing async-context propagation in thestudio uiserver. It fails quietly, which is why it only ever showed up as a build warning. After the fix the same code emits__require("async_hooks"), resolving to the real module via thecreateRequireshim the config already installs per chunk.No user-visible behaviour change is expected; the
studio uiserver regains correct async-context propagation.Testing Instructions
npm start— the config-loader andasync_hooksexternalization warnings should be gone.npm run cli:build && npm run cli:build:ui— both clean.grep -r "vite_browser_external" apps/cli/dist/cli/*.mjsreturns nothing, andgrep -r "async_hooks" apps/cli/dist/cli/*.mjsshows__require("async_hooks").grep -rn 'from "express"' apps/cli/dist/cli/*.mjsreturns nothing (express stays bundled).node apps/cli/dist/cli/main.mjs ui --no-open --port 8099, then check/index.local.html→ 200,/api/sites→ 200, and a POST with a JSON body → 400 (exercises theraw-bodypath).npm test -- --tagsFilter='!e2e'andnpm run typecheck.Pre-merge Checklist
🤖 Generated with Claude Code