/vite-wasm-node14-bug

PoC for a Vite bug when inlining WebAssembly for libraries

Primary LanguageJavaScriptMIT LicenseMIT

This repository demonstrates a bug in Vite, which causes library builds with inlined .wasm files to fail on Node.js < v16.

Prerequisites

You must have Node.js < 16 and NPM ≥ 7. I recommend switching Node.js versions using nvm or nvm-windows.

There are two branches in this repository:

How to reproduce (without building WebAssembly)

This repository contains a pre-built .wasm file, so that you can reproduce the bug without installing the Rust toolchain:

npm install --omit=optional
npm run build
npm start

How to reproduce

If you have installed the Rust toolchain on your system, you can reproduce the bug by building the WebAssembly module yourself:

npm install
npm run build-wasm
npm run build
npm start

Expected result

$ npm start

123 + 456 = 579

Actual result

$ npm start

ReferenceError: atob is not defined
    at initWasm (file:///~/vite-wasm-node14-bug/dist/index.js:4:26)
    at wasmInit (file:///~/vite-wasm-node14-bug/dist/index.js:22:28)
    at file:///~/vite-wasm-node14-bug/dist/index.js:27:24
    at file:///~/vite-wasm-node14-bug/dist/index.js:34:3
    ...