Closed ESchouten closed 8 months ago
Sorry but I don't really know alot about Vite/ESBuild so it might be hard for me to help. I've asked in the foxglove slack about this problem and they said "Not familiar either but I don’t think this issue is specific to the foxglove library because it claims there is a top level await in what appears to be code generated by vite itself (not the original .wasm file in the library)"
I've only been testing this library with webpack and it doesn't take too much to get it working there so I'm thinking there's probably a simple fix to this
Would this project maybe help/fix the problem? https://www.npmjs.com/package/vite-plugin-wasm
Is there a project you have that I can clone to mess around with and see if I can fix the issue?
Will create a project for you soon. Currently I have swapped out wasm-bz2 for compressjs
decompressedData = compressjs.Bzip2.decompressFile(bzData);
I was actually using a different bz2 library before this one but it had a small problem. Basically 1 bit would be off after decompressing and it would only happen with some cache versions. I have no idea what causes it but all those issues went away when I switch to this current bz2 library. I'm guessing there's probably some weird JS nuance going on that caused it and since this library is a wasm compilation of the official bz2 implementation it should always work.
If the one that you linked does work with multiple different caches I'd be fine switching over to it.
I ran the Load NPC tests which loads the cache, all bz2 compressed idx files seemed to return the same UInt8Array with wasm-bz2 as with compressjs. Have only tried one OSRS cache version though. Will open a PR.
Demo project here: https://github.com/ESchouten/svelte-osrscachereader Pinned osrscachereader>web-worker dependency to 1.2.0, 1.3.0 causes some import error. Added vite-plugin-wasm and vite-plugin-top-level-await, excluded env and wasi_snapshot_preview1 from dependency optimisation which made them disappear.
Seems like bundlers using ESBuild like Vite are not able to use this library since ESBuild does not support top-level awaits which the used bzip2 library @foxglove/wasm-bz2 is using. Any solution to this? Or do we have to swap out the bzip2 library?
Error: