Unify Node.js WASM import namespace with other targets#4869
Merged
guybedford merged 2 commits intoDec 20, 2025
Conversation
ac519fb to
03764ce
Compare
Member
Author
|
CI shows a flaky test failure that should have been resolved in #4857 — unclear why it regressed. |
There was a problem hiding this comment.
Pull request overview
This PR unifies the WASM import namespace for Node.js targets from __wbindgen_placeholder__ to ./{name}_bg.js, completing the cross-target alignment started in PR #4850. This enables WASM modules to be shared across different build targets (web, bundler, Node.js).
- Updates Node.js target (both CommonJS and ESM) to use the new
./{name}_bg.jsimport namespace - Modifies both JavaScript import generation and WASM module import mutations
- Updates all reference test files to reflect the new namespace and resulting import order changes
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
crates/cli-support/src/js/mod.rs |
Core implementation: adds module_name parameter to generate_node_imports() and updates namespace string generation for Node CommonJS mode; adds import module mutation for Node CommonJS to match existing Bundler/ESM pattern |
crates/cli/tests/reference/targets-target-nodejs.wat |
Test reference: updates WASM imports from __wbindgen_placeholder__ to ./reference_test_bg.js |
crates/cli/tests/reference/targets-target-nodejs.js |
Test reference: updates JavaScript imports object key from __wbindgen_placeholder__ to ./reference_test_bg.js |
crates/cli/tests/reference/targets-target-nodejs-mvp.wat |
Test reference: updates WASM imports for MVP target variant |
crates/cli/tests/reference/targets-target-nodejs-mvp.js |
Test reference: updates JavaScript imports for MVP target variant |
crates/cli/tests/reference/targets-target-nodejs-atomics.wat |
Test reference: updates WASM imports for atomics/threading target variant |
crates/cli/tests/reference/targets-target-nodejs-atomics.js |
Test reference: updates JavaScript imports for atomics/threading target variant |
crates/cli/tests/reference/import-target-nodejs.wat |
Test reference: updates WASM imports and reflects natural WASM import reordering due to module name change (. sorts before _) |
crates/cli/tests/reference/import-target-nodejs.js |
Test reference: updates JavaScript imports for complex import scenario |
CHANGELOG.md |
Documents the breaking change under "Changed" section with appropriate context |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Change the Node.js (CommonJS) WASM import namespace from
`__wbindgen_placeholder__` to `./{name}_bg.js`, matching the import
convention used by the `bundler` and `experimental-nodejs-module`
targets.
Changes:
* Update `generate_node_imports` to accept a `module_name` parameter.
* Replace `PLACEHOLDER_MODULE` / `__wbindgen_placeholder__` with
`./{module_name}_bg.js` when emitting Node.js imports.
* Set the `import.module` field for WASM imports in the Node.js target to
the same `./{module_name}_bg.js` value.
Part of the cross-target WASM sharing initiative (#4850).
03764ce to
d045b4e
Compare
guybedford
approved these changes
Dec 18, 2025
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.
Description
This is a follow-up to PR #4850, which unified WASM import namespaces for
web,no-modules,esm, andbundlertargets. The Node.js target still used the legacy__wbindgen_placeholder__namespace, preventing full cross-target WASM sharing.Node.js Target WASM Import Namespace
Changed the WASM import namespace for
--target nodejsfrom__wbindgen_placeholder__to./{name}_bg.js:JavaScript Import Changes
Checklist