Skip to content

fix(@angular/build): enable oxc WASI fallback in WebContainer environments - #34628

Merged
alan-agius4 merged 4 commits into
angular:mainfrom
alan-agius4:fix/webcontainer-oxc-wasi-fallback
Nov 2, 2026
Merged

alan-agius4 merged 4 commits into
angular:mainfrom
alan-agius4:fix/webcontainer-oxc-wasi-fallback

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.

Closes #34623
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

@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 resolve an upstream compatibility issue with @oxc-parser/binding-wasm32-wasi in WebAssembly environments like WebContainers. The shim is imported in several OXC tools, and a new E2E test is added to verify WASI functionality. Feedback on the changes highlights a potential issue with modifying Object.prototype using a getter-only property, which can cause TypeErrors in strict mode when other code attempts to assign to addonModule. It is recommended to add a setter to allow the property to be safely shadowed.

@alan-agius4
alan-agius4 requested a review from clydin November 2, 2026 09:42
@alan-agius4 alan-agius4 added action: review The PR is still awaiting reviews from at least one requested reviewer target: minor This PR is targeted for the next minor release labels Nov 2, 2026
Comment thread packages/angular/build/package.json Resolved
Comment thread tests/e2e/tests/vite/wasi.ts Resolved
Comment thread tests/e2e/tests/vite/wasi.ts 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 fd8e743 into angular:main Nov 2, 2026
40 checks passed
@alan-agius4
alan-agius4 deleted the fix/webcontainer-oxc-wasi-fallback branch November 2, 2026 17:05
@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: minor This PR is targeted for the next minor release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build: ERR_REQUIRE_CYCLE_MODULE when loading oxc-parser in StackBlitz / WebContainer

2 participants