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

🙋 WASM support for Node targets #1070

Closed
davidnagli opened this issue Mar 25, 2018 · 2 comments
Closed

🙋 WASM support for Node targets #1070

davidnagli opened this issue Mar 25, 2018 · 2 comments

Comments

@davidnagli
Copy link
Contributor

🙋 Feature Request

Currently if you run Parcel on a project that uses WASM (I tried it on Rust), the output uses fetch() to get the .wasm file. We should detect if target is 'node', and use fs instead of fetch.

As far as I understood WASM is already supported in Node 8 and Node 9.

Running the way it is, I get the following error:

$ node dist/index.js
/Users/davidnagli/Desktop/coding/playground/parcel-rust-test/dist/index.js:8
module.exports=function(t){return fetch(t).then(function(t){return WebAssembly.instantiateStreaming?WebAssembly.instantiateStreaming(t):t.arrayBuffer().then(function(t){return WebAssembly.instantiate(t)})}).then(function(t){return t.instance.exports})};
                           ^

ReferenceError: fetch is not defined
    at module.exports (/Users/davidnagli/Desktop/coding/playground/parcel-rust-test/dist/index.js:8:28)
    at u (/Users/davidnagli/Desktop/coding/playground/parcel-rust-test/dist/index.js:6:610)
    at Array.map (<anonymous>)
    at Function.t [as load] (/Users/davidnagli/Desktop/coding/playground/parcel-rust-test/dist/index.js:6:303)
    at Object.require.0 (/Users/davidnagli/Desktop/coding/playground/parcel-rust-test/dist/index.js:10:50)
    at t (/Users/davidnagli/Desktop/coding/playground/parcel-rust-test/dist/index.js:1:408)
    at /Users/davidnagli/Desktop/coding/playground/parcel-rust-test/dist/index.js:1:646
    at Object.<anonymous> (/Users/davidnagli/Desktop/coding/playground/parcel-rust-test/dist/index.js:1:663)
    at Module._compile (module.js:649:30)
    at Object.Module._extensions..js (module.js:660:10)

Repo to Reproduce

Here's where that fetch() comes from:

module.exports = function loadWASMBundle(bundle) {
return fetch(bundle)
.then(function (res) {
if (WebAssembly.instantiateStreaming) {
return WebAssembly.instantiateStreaming(res);
} else {
return res.arrayBuffer()
.then(function (data) {
return WebAssembly.instantiate(data);
});
}
})
.then(function (wasmModule) {
return wasmModule.instance.exports;
});
};

@fathyb
Copy link
Contributor

fathyb commented Mar 25, 2018

Maybe duplicate of #969, #981 fixes it

@davidnagli
Copy link
Contributor Author

Oh cool 👍 😃

@davidnagli davidnagli changed the title 🙋 Add support WASM support for Node targets 🙋 WASM support for Node targets Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants