Skip to content

Latest commit

 

History

History
35 lines (21 loc) · 1.14 KB

readme.md

File metadata and controls

35 lines (21 loc) · 1.14 KB

HELP: Vite + Wasm + CommonJS?

I'm trying to the zbar.wasm package to import with vite.

It's shipped as commonJS, but uses a .bin file to get around some webpack issues:

samsam2310/zbar.wasm#21

Now I can't figure out how to import the thing into a vite project. I've tried:

  1. import { scanImageData } from 'zbar.wasm';
  2. import { instantiate } from './node_modules/zbar.wasm/dist/zbar.js'
  3. import { loadWasmInstance } from './node_modules/zbar.wasm/dist/load'
  4. import { loadWasmInstance } from './node_modules/zbar.wasm/dist/load-browser'

I think the issue is around vite not knowing how to handle the .bin file. For this, I tried modifying the shipped code with ?url on the end, no dice.

Reproduction

  1. npm install
  2. npm start
  3. Visit the server in your browser.

See this:

✘ [ERROR] No loader is configured for ".bin" files: node_modules/zbar.wasm/dist/zbar.wasm.bin

    node_modules/zbar.wasm/dist/load-browser.js:15:48:
      15 │ const zbar_wasm_bin_1 = __importDefault(require("./zbar.wasm.bin"));~~~~~~~~~~~~~~~~~