Skip to content

fix: pass onWarn to viteResolvePlugin in build mode#22487

Open
toshetah wants to merge 1 commit into
vitejs:mainfrom
toshetah:main
Open

fix: pass onWarn to viteResolvePlugin in build mode#22487
toshetah wants to merge 1 commit into
vitejs:mainfrom
toshetah:main

Conversation

@toshetah
Copy link
Copy Markdown

Fixes the Rolldown NAPI panic that crashes vite build when builtin:vite-resolve needs to emit a warning.

Problem

In build mode, viteResolvePlugin was not passed an onWarn callback. When the native builtin:vite-resolve NAPI plugin encountered a condition requiring a warning, it fell back to calling this.warn() on its Rust plugin context — which is marked unimplemented!() in Rolldown, causing a hard panic:

thread 'rolldown-worker' panicked at crates/rolldown_plugin/src/plugin_context/plugin_context.rs:
not implemented: Can't call warn on PluginContext::Napi

The onWarn callback was already provided in serve mode but was missing from the build mode branch.

Fix

Remove the command === 'serve' conditional so onWarn is passed unconditionally, routing warnings through Vite's logger in both modes.

Tests

A test is not included because the panic occurs inside Rolldown's native binary and cannot be reproduced in Vite's JS test suite. The fix is structural — onWarn was already exercised in serve mode; this change makes it unconditional.

Alternatives explored

  • Suppressing the warning at the Rolldown level via rolldownOptions.checks flags — those are JS-level config, the Rust panic fires before they are consulted
  • Using createBuilder with useLegacyBuilder: true — controls the Environment API shape only, Rolldown is still used either way

In build mode, viteResolvePlugin was not passed an onWarn callback.
When builtin:vite-resolve (a Rolldown NAPI plugin) needed to emit a
warning, it fell back to calling this.warn() on its native Rust
context, which is marked unimplemented!() — causing a hard panic.

The callback was already provided in serve mode. Making it
unconditional fixes the panic and routes warnings through Vite's
logger in both modes.
@toshetah
Copy link
Copy Markdown
Author

The three failing checks are pre-existing CI issues unrelated to this change:

  • node-20: pnpm@10.33.4 panics with ERR_UNKNOWN_BUILTIN_MODULE on Node.js 20 (infrastructure issue, fails before install)
  • macos-latest: same "Test build" failure exists on main prior to this PR
  • zizmor: pre-existing workflow security scan failure on main

The code change itself is a one-line fix removing a serve-mode guard from the onWarn callback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant