Skip to content

Commit

Permalink
fix #2683: esbuild-wasm broken in node v19
Browse files Browse the repository at this point in the history
  • Loading branch information
evanw committed Nov 20, 2022
1 parent ecc9eeb commit daccf02
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## Unreleased

* Fix the `esbuild-wasm` package in Node v19 ([#2683](https://github.com/evanw/esbuild/issues/2683))

A recent change to Node v19 added a non-writable `crypto` property to the global object: https://github.com/nodejs/node/pull/44897. This conflicts with Go's WebAssembly shim code, which overwrites the global `crypto` property. As a result, all Go-based WebAssembly code that uses the built-in shim (including esbuild) is now broken on Node v19. This release of esbuild fixes the issue by reconfiguring the global `crypto` property to be writable before invoking Go's WebAssembly shim code.

* Fix CSS dimension printing exponent confusion edge case ([#2677](https://github.com/evanw/esbuild/issues/2677))

In CSS, a dimension token has a numeric "value" part and an identifier "unit" part. For example, the dimension token `32px` has a value of `32` and a unit of `px`. The unit can be any valid CSS identifier. The value can be any number in floating-point format including an optional exponent (e.g. `-3.14e-0` has an exponent of `e-0`). The full details of this syntax are here: https://www.w3.org/TR/css-syntax-3/.
Expand Down
10 changes: 10 additions & 0 deletions npm/esbuild-wasm/bin/esbuild
Expand Up @@ -129,5 +129,15 @@ for (let key in process.env) {
}
}

// Node v19 introduced "globalThis.crypto" https://github.com/nodejs/node/pull/44897.
// This broke Go's WebAssembly shim: https://github.com/golang/go/issues/56860.
// Hack around this breakage by resetting "globalThis.crypto" to "writable".
// Just to be safe, also make it "configurable" in case Go updates their
// compiler such that it tries to reconfigure "globalThis.crypto" itself.
Object.defineProperty(globalThis, 'crypto', {
writable: true,
configurable: true,
});

process.argv.splice(2, 0, esbuild_wasm);
wrapper(module_.createRequire(wasm_exec_node), Object.assign(Object.create(WebAssembly), { instantiate }));

0 comments on commit daccf02

Please sign in to comment.