Skip to content
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

Library bundle with inlined WASM fails in Node < 16 #8620

Closed
7 tasks done
pastelmind opened this issue Jun 16, 2022 · 0 comments · Fixed by #8622
Closed
7 tasks done

Library bundle with inlined WASM fails in Node < 16 #8620

pastelmind opened this issue Jun 16, 2022 · 0 comments · Fixed by #8622
Labels
feat: wasm p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@pastelmind
Copy link
Contributor

Describe the bug

A library (built with build.lib) with inlined WebAssembly (.wasm) files fails in Node.js < 16. This is because the Vite-generated bindings use atob(), which is available only in Node.js 16+.

The binding code is:

if (url.startsWith('data:')) {
// @ts-ignore
const binaryString = atob(url.replace(/^data:.*?base64,/, ''))
const bytes = new Uint8Array(binaryString.length)
for (let i = 0; i < binaryString.length; i++) {
bytes[i] = binaryString.charCodeAt(i)
}
// @ts-ignore
result = await WebAssembly.instantiate(bytes, opts)
} else {

Although Vite is primarily geared towards web browsers, Vite's Library Mode is useful for developing isomorphic libraries that must support browsers and Node.js. Since Node.js v14 has plenty of time to reach EOL (due April 2023), it would be great to support it.

Reproduction

https://github.com/pastelmind/vite-wasm-node14-bug

System Info

System:
    OS: macOS 12.4
    CPU: (8) x64 Apple M1
    Memory: 147.27 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 14.19.3 - ~/.nvm/versions/node/v14.19.3/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v14.19.3/bin/yarn
    npm: 8.12.1 - ~/.nvm/versions/node/v14.19.3/bin/npm
  Browsers:
    Chrome: 102.0.5005.115
    Firefox: 101.0
    Safari: 15.5
  npmPackages:
    vite: ^2.9.12 => 2.9.12

Used Package Manager

npm

Logs

No response

Validations

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: wasm and removed pending triage labels Jun 17, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jul 2, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feat: wasm p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants