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

WMR does not load WASM files from node_modules #412

Open
aduh95 opened this issue Mar 9, 2021 · 4 comments
Open

WMR does not load WASM files from node_modules #412

aduh95 opened this issue Mar 9, 2021 · 4 comments
Labels
bug Something isn't working

Comments

@aduh95
Copy link
Contributor

aduh95 commented Mar 9, 2021

Describe the bug

WMR doesn't work well with packages that ship WASM binaries. I'd like to bundle a WASM file with my application and give its URL to the Emscripten module that loads it, but it seems WMR doesn't let me do that.

To Reproduce

yarn create wmr your-project-name
cd your-project-name
mkdir node_modules/test
curl -L https://github.com/mathiasbynens/small/raw/master/webassembly.wasm > node_modules/test/test.wasm
echo '{"name":"test","exports":"./test.wasm"}' > node_modules/test/package.json
echo 'export { default } from "url:test";' > public/index.js
yarn wmr build

This produces the following error message:

Could not load urlnpm/test/test.wasm (imported by public/index.js): ENOENT: no such file or directory, open npm/test/test.wasm'
error Command failed with exit code 1.

Expected behavior

I would expect WASM file to be treated as any other file. If there's a good reason to treat them differently, I'd like to find documentation on why this is not the case, and ideally having an option to chose which behaviour I want.

Additional context

If I want to do the same thing with Rollup, I have to use the @rollup/plugin-url:

import url from "@rollup/plugin-url";

export default {
  
  plugins: [
    url({
      include: "**/*.wasm",
    }),
  ],
};

I don't know if it's related, but I've also noticed that if I try to use a npm package that includes a WASM binary yarn add it, the WASM file is not even downloaded.

$ echo 'export { default } from "url:@aduh95/viz.js/wasm";' > public/index.js
$ yarn wmr build
Could not load urlnpm/@aduh95/viz.js@3.3.3/dist/render.wasm (imported by public/index.js): ENOENT: no such file or directory, open npm/@aduh95/viz.js@3.3.3/dist/render.wasm'
$ ls node_modules/@aduh95/viz.js/dist/render.wasm
$ yarn add @aduh95/viz.js
$ ls node_modules/@aduh95/viz.js/dist/render.wasm
node_modules/@aduh95/viz.js/dist/render.wasm
$ yarn wmr build
Could not load urlnpm/@aduh95/viz.js@3.3.3/dist/render.wasm (imported by public/index.js): ENOENT: no such file or directory, open npm/@aduh95/viz.js@3.3.3/dist/render.wasm'
@aduh95 aduh95 added the bug Something isn't working label Mar 9, 2021
@developit
Copy link
Member

Ah yes, we're filtering out wasm by accident.

Barring that, you can use the URL prefix to load WASM:

import url from 'url:./foo.wasm';
@aduh95
Copy link
Contributor Author

aduh95 commented Mar 26, 2021

@developit Thanks for the answer, however it seems it doesn't apply to WASM files inside node_modules folder:

rm -r your-project-name
yarn create wmr your-project-name
cd your-project-name
mkdir node_modules/test
curl -L https://github.com/mathiasbynens/small/raw/master/webassembly.wasm > public/test.wasm
echo '{"name":"test"}' > node_modules/test/package.json
echo 'export { default } from "url:test/test.wasm";' > public/index.js
yarn wmr build
Could not load urlnpm/test/test.wasm (imported by public/index.js): ENOENT: no such file or directory, open npm/test/test.wasm'

It does work for WASM file in the same directory (as in your example), so there's something related with the path resolution of node_modules I suppose.

@developit
Copy link
Member

Ah yeah that's possible. Is this after running npm install to ensure the file is there? We don't currently stream wasm to disk during auto-install.

@aduh95
Copy link
Contributor Author

aduh95 commented Mar 26, 2021

Is this after running npm install to ensure the file is there?

Running npm install doesn't seem to help, the build fails anyway even though the WASM file is on the disk.

@marvinhagemeister marvinhagemeister changed the title WMR does not load WASM files Jul 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
2 participants