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

doesn't work anymore in browser #13

Open
atonamy opened this issue Mar 13, 2020 · 11 comments
Open

doesn't work anymore in browser #13

atonamy opened this issue Mar 13, 2020 · 11 comments

Comments

@atonamy
Copy link

atonamy commented Mar 13, 2020

After installation of the package if we try to use it in the browser it will throw the error when u call
zlib_decode_raw or any other function:

uncaught RuntimeError: unreachable at __rust_start_panic (wasm-function[322]:0x1c795) at rust_panic

If we try to rebuild package from source code using
wasm-pack build --target no-modules -- --features "browser strings"

after that it will throw:

Uncaught TypeError: Cannot read property '__wbindgen_malloc' of undefined

To reproduce this issue use version of Chrome 80.0.3987.132

@mindplay-dk
Copy link

Similar problem here - I get malloc is not a function

Here's a sandbox exhibiting this problem:

https://codesandbox.io/s/runtime-wave-0owk6

I've also tried going back a few versions, and couldn't find one that works.

@gunnim
Copy link

gunnim commented Apr 11, 2020

@mindplay-dk
0.1.12 in-browser https://codesandbox.io/s/wasm-flate-browser-gf8zt
1.0.2-bundler also works for me https://codesandbox.io/s/wasm-flate-bundler-gxshx

And i ended up following the instructions here to get it working in cra
https://www.telerik.com/blogs/using-webassembly-with-react

@mindplay-dk
Copy link

@gunnim

0.1.12 in-browser https://codesandbox.io/s/wasm-flate-browser-gf8zt

Wrong link? This doesn't list wasm-flate in it's dependencies.

1.0.2-bundler also works for me https://codesandbox.io/s/wasm-flate-bundler-gxshx

Unsaved changes?

This only imports from wasm-flate - and injects it into window for some reason?

image

And it doesn't appear to make any calls to any imported functions?

I have tried many prior versions and just get different errors....

@gunnim
Copy link

gunnim commented Apr 15, 2020

@mindplay-dk I see my previous comment could have used a little more clarification :)

So the 0.1.12 sandbox includes wasm-flate in it's index.html file

In both cases i confirmed wasm-flate works simply by running flate. in the sandbox console.

Like I mentioned previously I am currently using the 1.0.2-bundler in a pet project of mine hosted here with great success.

@mindplay-dk
Copy link

@gunnim could you update your bundler sandbox, please?

There's no actual call in your sandbox, it's just an import - which is as far as I got myself.

You probably have local changes that were never saved?

I inserted a call in your sandbox myself - so:

import * as React from "react";
import { render } from "react-dom";

import App from "./App";
import * as flate from "wasm-flate";

(window as any)["flate"] = flate;

console.log(
  flate.deflate_encode_raw(new Uint8Array(Buffer.from("hello hello world world world"))).length
);

const rootElement = document.getElementById("root");
render(<App />, rootElement);

And I get the exact same error as in my sandbox:

image

I can see this working with the in-browser build loading it globally - what I'd really like to see is a sandbox with a working import and an actual call.

Still no luck here.

@Junior2Ran
Copy link

same problem, gan

@gunnim
Copy link

gunnim commented Dec 10, 2020

Sorry about the late reply @mindplay-dk and hope this motivates you as well @Junior2Ran

Now the 1.0.2 build does in fact fail with a malloc error in browser, that is correct. I am however using the 1.0.2-bundler build successfully following the instructions I linked above.

The 0.1.12 however, with dependency in index.html, does work. Shown on the accompanying screenshot. Hopefully this unblocks someone wanting to try out the package until @drbh takes a look at the 1.0.2-browser build :)

working

@Junior2Ran
Copy link

0.1.12 is fine indeed.
But the problem is when using 1.0.2-browser as script in html like 0.1.12, the error goes to flate not defined, and when using 1.0.2-bundler in esmodule like import * as flate from 'wasm-flate', the error goes to malloc is not a function

@limcheekin
Copy link

Almost 2 years now, anyone here managed to get the wasm-flate@1.0.2-browser working in the browser?

Appreciate if you could share code example here.

Thank you.

@RunbinPeng
Copy link

Almost 2 years now, anyone here managed to get the wasm-flate@1.0.2-browser working in the browser?

Appreciate if you could share code example here.

Thank you.

@limcheekin I studied the bundled js file and successfully found how to use it.

  1. Add script tag to your html.
    <script onload="wasm_bindgen('https://cdn.jsdelivr.net/npm/wasm-flate@1.0.2-browser/wasm_flate_bg.wasm')" src=" https://cdn.jsdelivr.net/npm/wasm-flate@1.0.2-browser/wasm_flate.min.js "></script>
  2. All those functions are in the global object wasm_bindgen, for example:
wasm_bindgen.gzip_decode_raw( u8intArray )

However, I observed that the speed of this library is much lower than fflate. don't know why

@limcheekin
Copy link

limcheekin commented Nov 21, 2023

Thanks for the helpful response.

I just switched to the fflate last week.

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

6 participants