Repository navigation
fix(@angular/build): enable oxc WASI fallback in WebContainer environments (22.2.x) - #34629
Conversation
…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)
There was a problem hiding this comment.
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.
This comment was marked as resolved.
This comment was marked as resolved.
|
This PR was merged into the repository. The changes were merged into the following branches:
|
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.0specifies@emnapi/core@2.0.0-alpha.6while 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,initWorkeris assigned toemnapi_shared.addonModule, which is undefined in alpha.6 (where it was namednapiModule), throwingTypeError: Cannot set properties of undefined (setting 'initWorker').This PR introduces
oxc-wasi-shim, which aliasesaddonModuletothis.napiModuleonObject.prototypewhen running in WebContainer or whenNAPI_RS_FORCE_WASIis enabled, allowing the WASI runtime to initialize successfully. In addition,@oxc-parser/binding-wasm32-wasiis removed fromoptionalDependenciessince oxc-parser's built-in WebContainer fallback downloads and loads it on demand.An end-to-end test verifying
ng servewithNAPI_RS_FORCE_WASI=trueis also included.Backport of #34628
Fixes #34524