Fix direct native ESM imports on Vite 7 and 8 - #20
Merged
Conversation
biw
force-pushed
the
biw/fix-direct-native-imports
branch
from
August 8, 2026 00:16
1746688 to
18e513c
Compare
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.
Summary
Direct ESM imports of
.nodefiles could be claimed by Vite's generic asset handling before this plugin resolved them, causing the binary to be parsed as JavaScript. This child PR resolves native imports first and adds regression coverage on Vite 7.3.6 and 8.2.1.What This PR Does
.nodeESM import builds in both.What This Improves
import addon from "./addon.node"now bundles successfully with the plugin's normal configuration on Vite 7 and Vite 8.What This Does Not Do
Important Context
biw/migrate-to-vite-plus); review and merge that tooling PR first.Code To Review Closely
src/index.ts:740The resolver must run before Vite classifies the
.nodeimport as a generic asset. The generated asset hook is separately ordered last atsrc/index.ts:1704so native files remain visible after tree-shaking.Gotchas, Risks, And Edge Cases
null.Tests And Regression Coverage
Validation Run
vp check: passed.vp run test: passed, 197 tests.vp pack: passed.Coverage Assessment
Sufficient for the reported bundling regression: the new test creates a direct static
.nodeESM import and builds it through the normal plugin configuration against both Vite 7.3.6 and Vite 8.2.1. Existing tree-shaking coverage verifies that used native assets are still emitted.Regressions These Tests Should Catch
Gaps And Recommended Follow-Up Tests
Follow-Up Work