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

Support targeting Node #266

Closed
nikgraf opened this issue Aug 24, 2018 · 6 comments
Closed

Support targeting Node #266

nikgraf opened this issue Aug 24, 2018 · 6 comments

Comments

@nikgraf
Copy link
Contributor

nikgraf commented Aug 24, 2018

💡 Feature description

I was trying @xtuc's wasm-node-loader, but noticed the output of wasm-pack is not compatible to Node 10.

Three things I noticed:

  • the file ending of the generated JS file is .js, but node will require a .mjs ending.
  • import of the wasm file not ending with .wasm. e.g. import * as wasm from './app_bg'; . With the node loader it should be import * as wasm from './app_bg.wasm.
  • after I changed them manually node was still complaining it can't fine "./app.js", but not sure where this was coming from.

I'm not sure what's the best way forward. wasm-pack could support a commnand line flag for wasm-pack build to target node. On the other hand maybe it needs a different node loader.

@nikgraf nikgraf changed the title Support a targed Node Support targeting Node Aug 24, 2018
@mgattozzi
Copy link
Contributor

Hey @nikgraf so this is doable. However, the major blocker is wasm-bindgen until that gets support for Node modules we won't be able to move this forward, because otherwise we'd be parsing JS files to do the transform rather than wasm-bindgen spitting them out automatically as .mjs files with the correct import statements.

@nikgraf
Copy link
Contributor Author

nikgraf commented Aug 26, 2018

Thanks for the clarification 👍

@ashleygwilliams
Copy link
Member

hey @nikgraf - so wasm-pack can support node by exporting CommonJS. would this work for you? we aren't currently of the impression that es6 modules on node are stable enough to support. you would need nodejs with a flag, which also still has bugs and edgecases, and we don't have a way to give reliable commonjs fallback either, which is frustrating.

let me know if the CommonJS use case works for you! you can use it by running wasm-pack init --target nodejs

@xtuc
Copy link
Member

xtuc commented Sep 24, 2018

This isn't blocking to me.

The issue is that the current ESM implementation in bundler and the future one in Nodejs, will have some differences, .mjs is an example.

I wouldn't work on making ESM for bundler also compatible for Nodejs.

@nikgraf
Copy link
Contributor Author

nikgraf commented Oct 2, 2018

@ashleygwilliams just tried it and works like a charm. I thought loading WASM won't work with CommonJS, but I does just fine. Thanks!

@nikgraf nikgraf closed this as completed Oct 2, 2018
@ashleygwilliams
Copy link
Member

Great to hear! Glad it worked for you :)

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

4 participants