perspective icon indicating copy to clipboard operation
perspective copied to clipboard

Errors updating to 3.0.0/3.0.1 with Svelte / Vite

Open marklbarlow opened this issue 1 year ago • 5 comments

Bug Report

Using Svelte / Vite and upgrading from v2 to v3, I get a strange import error.

Screenshot 2024-08-29 at 20 18 08

Issue is reproduced in this repo:

https://github.com/marklbarlow/perspective-svelte

with the changes for v3 in this commit:

https://github.com/marklbarlow/perspective-svelte/commit/7b262c54f0d4417fe5ce4286c147818487c06ae1

What am I missing?

marklbarlow avatar Aug 29 '24 19:08 marklbarlow

might wanna see #2724 i faced a similar issue i think it has something to with how the packages are being loaded )remember reading something briefly in the release on changes to javascript) not sure, but passing the PerspectivePlugin to my webpack config resolved the issue i think it might work out for you too.

Nipunx1999 avatar Aug 29 '24 19:08 Nipunx1999

I’m using vite (which uses esbuild under the hood) rather than webpack, but I did try the esbuild plugin as well. Still didn’t have any luck unfortunately. As the authors have mentioned in a different thread, I think the plugins are just there to help reduce bundle size rather than being mandatory, so hopefully it’s just a config option I missing?

marklbarlow avatar Aug 29 '24 20:08 marklbarlow

Im not entirely sure, but in my case unless i added the plugin the build itself would fail this never happened before verson 3.0 i didnt use anything extra earlier.

Nipunx1999 avatar Aug 29 '24 21:08 Nipunx1999

I’m using vite (which uses esbuild under the hood)

Vite uses esbuild only for dev builds to pre-bundle not for prod builds, instead it uses rollup instead see: https://vitejs.dev/guide/why.html#why-not-bundle-with-esbuild

NOTE Dependency pre-bundling only applies in development mode, and uses esbuild to convert dependencies to ESM. In production builds, @rollup/plugin-commonjs is used instead.

aszenz avatar Oct 01 '24 13:10 aszenz

I'm also having this issue. Have you managed to find a fix? Including PerspectiveEsbuildPlugin in vite plugins did not help.

superrnovae avatar Oct 11 '24 18:10 superrnovae

I found a potential workaround using the latest perspective v3.1.2 inline builds with vite, can see an example stackblitz in the comment here: https://github.com/finos/perspective/issues/2796#issuecomment-2438383909

rajsite avatar Oct 25 '24 17:10 rajsite

I managed to get it working by making those changes but unfortunately it then gives me a bunch of typing errors, so it's only a partial fix.

Screenshot 2024-10-28 at 12 33 26

This at least seems to confirm something is not right with the exports though so would be great if @texodus or someone else can come up with a fix.

marklbarlow avatar Oct 28 '24 12:10 marklbarlow

Version 3 is simply not compatible with Vite. Vite requires all WebAssembly modules to be imported with either the ?init or ?url arguments, neither of which are accounted for by Perspective. (The first returns a function that, when called, provides a WebAssembly.Instance, while the second returns the module's URL.) Attempt to simply import the default export will result in vite throwing an error, due to it being reserved for a future esm intergration for wasm. Additionally, for workers to function with Vite, they must be imported using the ?worker argument or the Worker constructor.

Source for wasm arguments: https://github.com/vitejs/vite/pull/8219 Source for web worker: https://v3.vitejs.dev/guide/features.html#web-workers

superrnovae avatar Nov 28 '24 18:11 superrnovae

Fetching wasm using URL relative to import.meta.url and passing the response to load_wasm_stage_0 seems to work in vite, and should theoretically be compatible with other bundlers. As for the worker, instantiating it using new Worker() with module option and relative path also seems to work.

superrnovae avatar Nov 29 '24 09:11 superrnovae

Fetching wasm using URL relative to import.meta.url and passing the response to load_wasm_stage_0 seems to work in vite, and should theoretically be compatible with other bundlers. As for the worker, instantiating it using new Worker() with module option and relative path also seems to work.

could you please provide a code snippet regarding this ? as well as the vite.config file? It would help a lot in trobleshooting

MPizzotti avatar Dec 10 '24 14:12 MPizzotti

We've released Perspective 3.3.0 with official Vite support (docs) and sample project. This new unbundled build does not require a plugin, but does require special bundler setup (see docs).

For older Perspective versions (<= 3.2.1), we've tested the inline builds with Vite which still seem to work just fine. You may or may not be able to hack support together for non-esbuild bundlers for these versions, they were not designed to support this.

texodus avatar Jan 14 '25 23:01 texodus