Repository navigation
fix(@angular/build): enable oxc WASI fallback in WebContainer environments #34628
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
alan-agius4
merged 4 commits into
angular:main
from
alan-agius4:fix/webcontainer-oxc-wasi-fallback
Nov 2, 2026
+107
−0
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
cbc3888
fix(@angular/build): enable oxc WASI fallback in WebContainer environ…
alan-agius4 63fe012
fixup! fix(@angular/build): enable oxc WASI fallback in WebContainer …
alan-agius4 4d2137e
fixup! fix(@angular/build): enable oxc WASI fallback in WebContainer …
alan-agius4 9be932c
fixup! fix(@angular/build): enable oxc WASI fallback in WebContainer …
alan-agius4 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import { Module, createRequire } from 'node:module'; | ||
|
|
||
| // Workaround for an upstream incompatibility in `@oxc-parser/binding-wasm32-wasi` when | ||
| // falling back to WebAssembly (e.g., inside WebContainers or StackBlitz). | ||
| // | ||
| // `@oxc-parser/binding-wasm32-wasi` declares a dependency on `@emnapi/core@2.0.0-alpha.6`, | ||
| // but depends on `@napi-rs/wasm-runtime@~1.2.6` which expects `@emnapi/core@^1.7.1 || 2.0.0-beta.2`. | ||
| // 1. In `@napi-rs/wasm-runtime@1.2.6`, the runtime attempts to assign `initWorker` to | ||
| // `emnapi_shared.addonModule`, which is undefined in `alpha.6` where the property was named | ||
| // `napiModule`. Aliasing `addonModule` to `this.napiModule` on `Object.prototype` allows the | ||
| // WASI runtime to initialize successfully. | ||
| // 2. Under npm, `@napi-rs/wasm-runtime@1.2.6`'s peerDependencies cause npm to hoist `@emnapi/core@1.x` | ||
| // to top-level `node_modules` while nesting `2.0.0-alpha.6` under `@oxc-parser/binding-wasm32-wasi`, | ||
| // causing an ABI mismatch (`this.bridge.setLastError is not a function`). Under pnpm, `oxc-parser` | ||
| // does not declare `@oxc-parser/binding-wasm32-wasi` in its own dependencies. Resolving these | ||
| // packages relative to `@angular/build` and `@oxc-parser/binding-wasm32-wasi` ensures consistent | ||
| // module resolution across package managers. | ||
| // | ||
| // See: https://github.com/oxc-project/oxc/issues/28717 and https://github.com/napi-rs/napi-rs/issues/3674 | ||
| const forceWasi = globalThis.process?.env?.['NAPI_RS_FORCE_WASI']; | ||
| if ( | ||
| (globalThis.process?.versions?.['webcontainer'] || | ||
| forceWasi === 'true' || | ||
| forceWasi === 'error') && | ||
| !('addonModule' in Object.prototype) | ||
| ) { | ||
| Object.defineProperty(Object.prototype, 'addonModule', { | ||
| get() { | ||
| return (this as { napiModule?: unknown }).napiModule; | ||
| }, | ||
| set(value) { | ||
| if (this && (typeof this === 'object' || typeof this === 'function')) { | ||
| Object.defineProperty(this, 'addonModule', { | ||
| value, | ||
| writable: true, | ||
| configurable: true, | ||
| enumerable: true, | ||
| }); | ||
| } | ||
| }, | ||
| configurable: true, | ||
| enumerable: false, | ||
| }); | ||
|
|
||
| const resolvedModules = new Map<string, string>(); | ||
| try { | ||
| const wasiBindingPath = require.resolve('@oxc-parser/binding-wasm32-wasi'); | ||
| resolvedModules.set('@oxc-parser/binding-wasm32-wasi', wasiBindingPath); | ||
| const wasiRequire = createRequire(wasiBindingPath); | ||
| resolvedModules.set('@emnapi/core', wasiRequire.resolve('@emnapi/core')); | ||
| resolvedModules.set('@emnapi/runtime', wasiRequire.resolve('@emnapi/runtime')); | ||
| } catch {} | ||
|
|
||
| if (resolvedModules.size > 0) { | ||
| const moduleWithResolve = Module as typeof Module & { | ||
| _resolveFilename: ( | ||
| request: string, | ||
| parent: unknown, | ||
| isMain: boolean, | ||
| options: unknown, | ||
| ) => string; | ||
| }; | ||
| const origResolveFilename = moduleWithResolve._resolveFilename; | ||
| moduleWithResolve._resolveFilename = function (request, parent, isMain, options) { | ||
| const resolved = resolvedModules.get(request); | ||
| if (resolved !== undefined) { | ||
| return resolved; | ||
| } | ||
|
|
||
| return origResolveFilename.call(this, request, parent, isMain, options); | ||
| }; | ||
| } | ||
| } | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| import assert from 'node:assert'; | ||
| import { getGlobalVariable } from '../../utils/env'; | ||
| import { ng } from '../../utils/process'; | ||
|
|
||
| export default async function () { | ||
| assert( | ||
| getGlobalVariable('argv')['esbuild'], | ||
| 'This test should not be called in the Webpack suite.', | ||
| ); | ||
|
|
||
| const originalForceWasi = process.env['NAPI_RS_FORCE_WASI']; | ||
| process.env['NAPI_RS_FORCE_WASI'] = 'error'; | ||
|
|
||
| try { | ||
| await ng('build'); | ||
| } finally { | ||
| if (originalForceWasi === undefined) { | ||
| delete process.env['NAPI_RS_FORCE_WASI']; | ||
| } else { | ||
| process.env['NAPI_RS_FORCE_WASI'] = originalForceWasi; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.