Skip to content

fix(@angular/build): enable oxc WASI fallback in WebContainer environments (22.2.x) - #34629

Merged
alan-agius4 merged 3 commits into
angular:22.2.xfrom
alan-agius4:fix/webcontainer-oxc-wasi-fallback-22.2.x
Nov 2, 2026
Merged

alan-agius4 merged 3 commits into
angular:22.2.xfrom
alan-agius4:fix/webcontainer-oxc-wasi-fallback-22.2.x

Conversation

@alan-agius4

Copy link
Copy Markdown
Collaborator

In WebContainer environments (such as StackBlitz and angular.dev playground), native Node.js addons cannot run, requiring oxc-parser to fall back to WebAssembly (WASI).

However, @oxc-parser/binding-wasm32-wasi@0.156.0 specifies @emnapi/core@2.0.0-alpha.6 while depending on @napi-rs/wasm-runtime@~1.2.6 (which was updated for @emnapi/core@>=2.0.0-beta.2). In wasm-runtime 1.2.6, initWorker is assigned to emnapi_shared.addonModule, which is undefined in alpha.6 (where it was named napiModule), throwing TypeError: Cannot set properties of undefined (setting 'initWorker').

This PR introduces oxc-wasi-shim, which aliases addonModule to this.napiModule on Object.prototype when running in WebContainer or when NAPI_RS_FORCE_WASI is enabled, allowing the WASI runtime to initialize successfully. In addition, @oxc-parser/binding-wasm32-wasi is removed from optionalDependencies since oxc-parser's built-in WebContainer fallback downloads and loads it on demand.

An end-to-end test verifying ng serve with NAPI_RS_FORCE_WASI=true is also included.

Backport of #34628
Fixes #34524

…ments

In WebContainer environments (such as StackBlitz and angular.dev playground),
native Node.js addons cannot run, requiring oxc-parser to fall back to WebAssembly
(WASI).

However, @oxc-parser/binding-wasm32-wasi@0.156.0 specifies @emnapi/core@2.0.0-alpha.6
while depending on @napi-rs/wasm-runtime@~1.2.6 (which was updated for
@emnapi/core@>=2.0.0-beta.2). In wasm-runtime 1.2.6, initWorker is assigned to
emnapi_shared.addonModule, which is undefined in alpha.6 (where it was named
napiModule), throwing TypeError: Cannot set properties of undefined (setting 'initWorker').

Introducing oxc-wasi-shim aliases addonModule to napiModule on Object.prototype
when in WebContainer or when NAPI_RS_FORCE_WASI is enabled, allowing the WASI runtime
to initialize successfully. Additionally, remove @oxc-parser/binding-wasm32-wasi from
optionalDependencies as oxc-parser's built-in WebContainer fallback downloads and
loads it on demand.

Fixes angular#34524

(cherry picked from commit cbc3888)

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a workaround shim (oxc-wasi-shim.ts) to address an upstream dependency incompatibility in @oxc-parser/binding-wasm32-wasi when running in WebAssembly environments like WebContainers. The shim is imported across several OXC-related tools, and an E2E test is added to verify WASI functionality. A critical feedback item points out that modifying Object.prototype with a setter can cause runtime crashes (TypeError) when properties are assigned to primitive values in strict mode. A guard should be added to the setter to ensure this is an object or function before calling Object.defineProperty.

@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: patch This PR is targeted for the next patch release labels Nov 2, 2026
@alan-agius4

This comment was marked as resolved.

@alan-agius4 alan-agius4 added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Nov 2, 2026
@alan-agius4
alan-agius4 merged commit b5dd8e2 into angular:22.2.x Nov 2, 2026
35 checks passed
@alan-agius4
alan-agius4 deleted the fix/webcontainer-oxc-wasi-fallback-22.2.x branch November 2, 2026 17:59
@alan-agius4

Copy link
Copy Markdown
Collaborator Author

This PR was merged into the repository. The changes were merged into the following branches:

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

Labels

action: merge The PR is ready for merge by the caretaker area: @angular/build target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants