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

ES module support #4

Closed
zwz opened this issue Dec 18, 2019 · 9 comments
Closed

ES module support #4

zwz opened this issue Dec 18, 2019 · 9 comments

Comments

@zwz
Copy link

zwz commented Dec 18, 2019

I was trying wasm-flate by
import {deflate_encode_raw, deflate_decode_raw} from 'wasm-flate'

But it reports error when I visit the page related to wasm-flate

Failed to resolve module specifier "util". Relative references must start with either "/", "./", or "../".

TypeError: Failed to resolve module specifier "util". Relative references must start with either "/", "./", or "../".

I guess it was caused by the line 22 in wasm-flate.js.

@jimmykane
Copy link

@zwz did you manage to solve this?

@jimmykane
Copy link

I am getting

ERROR in ./node_modules/wasm-flate/wasm_flate_bg.js
Module not found: Error: Can't resolve 'fs' in '/Users/dimtrioskanellopoulos/Projects/track-tools/node_modules/wasm-flate'

@drbh any plans to make this an ES module with support for webpack ?

@jimmykane
Copy link

@drbh here is perhaps some help

https://www.sitepen.com/blog/getting-started-with-assemblyscript/

Here are my results on a 3K active user project that would love to get your benefit here

Screenshot 2019-12-25 at 19 28 44

@drbh
Copy link
Owner

drbh commented Dec 25, 2019

@jimmykane @zwz thanks for pointing this out - I’ll look into a way to avoid those dependencies after the holidays.

As for now I have a gist that loads wasm-flate in using a base64 string. This method is a bit hacky but is a possible workaround https://gist.github.com/drbh/24496aaa863b8faa549cd05cd939f587

Hopefully that helps in the mean time!

@jimmykane
Copy link

jimmykane commented Dec 26, 2019 via email

@drbh
Copy link
Owner

drbh commented Dec 27, 2019

Hey @jimmykane based on the code above, your webpack is failing on the fs module. fs is Node's filesystem module and is used to load the .wasm file into the runtime environment.

Loading the wasm file in this way is an artifact of wasm-flates build target flag. If you clone and build the repo with the --target bundler flag. It should produce a library that can be easily webpacked.

I built and deployed a new version (1.0-beta) https://www.npmjs.com/package/wasm-flate/v/0.1.0-beta and you'll see the code no longer has fs dependencies.

I have not had the chance to test this in any application - but this will likely solve, or start to solve the issue you have.

Hope this is helpful! Please let me know how it goes 😀

@jimmykane
Copy link

@drbh giving it a try today. Thank you so much.

My app is based on decoding a gzip packet client side that can be up to 50mb. You cannot imagine how much it has been speeded up !

@jimmykane
Copy link

Worked like a charm.

I had tried to compile this with another target as you instructed at my forked repo of this repo.

There was a little error, related to Angular and async loading of WebAssembly.

I leave this here for future reference in case people run to this issue

import('./app/app.module')
  .then(x => platformBrowserDynamic().bootstrapModule(x.AppModule))
  .catch(err => console.error(err));

rustwasm/wasm-bindgen#1559

@jimmykane
Copy link

So the beta release you just did worked! Should be working for other TS/ES projects just fine.

The above comment is only for angular

@drbh drbh closed this as completed Dec 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants