anthumchris / opus-stream-decoder

Instantly decode Ogg Opus audio streams in chunks with JavaScript & WebAssembly (Wasm)
124 stars 21 forks source link

"no such file" error when loaded as NPM package #3

Closed anthumchris closed 5 years ago

anthumchris commented 5 years ago

I published this repo as an NPM package to https://www.npmjs.com/package/opus-stream-decoder.

An error occurs when trying to use opus-stream-decoder after the NPM package is installed.

$ npm i opus-stream-decoder
$ node -e "require('opus-stream-decoder')"
{ Error: ENOENT: no such file or directory, open 'opus-stream-decoder.wasm'
    at Object.openSync (fs.js:448:3)
    at Object.readFileSync (fs.js:348:35)
    ...

One possible solution is to build with emcc --pre-js and declare function Module['locateFile'] that would return a valid path that Emscripten would use for the readFileSync() call.

anthumchris commented 5 years ago

@zandaqo Have you dealt with this before? I came across https://github.com/kripken/emscripten/issues/5342

zandaqo commented 5 years ago

@AnthumChris Indeed I have, it was a year ago and I chose to bundle my wasm and js into a single file with emcc — bind -std=c++14 src/wasm.cpp -s WASM=1 -O3 -o wasm.js, as done here: https://github.com/zandaqo/iswasmfast

But iswasmfast wasn't meant as a package, so I'd prefer locateFile in this case.