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

Errors updating to 3.0.0/3.0.1 with Svelte / Vite #2725

Open
marklbarlow opened this issue Aug 29, 2024 · 10 comments
Open

Errors updating to 3.0.0/3.0.1 with Svelte / Vite #2725

marklbarlow opened this issue Aug 29, 2024 · 10 comments

Comments

@marklbarlow
Copy link

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:

marklbarlow/perspective-svelte@7b262c5

What am I missing?

@Nipunx1999
Copy link

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.

@marklbarlow
Copy link
Author

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?

@Nipunx1999
Copy link

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.

@aszenz
Copy link
Contributor

aszenz commented Oct 1, 2024

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.

@superrnovae
Copy link

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

@rajsite
Copy link

rajsite commented Oct 25, 2024

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: #2796 (comment)

@marklbarlow
Copy link
Author

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.

@superrnovae
Copy link

superrnovae commented Nov 28, 2024

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: vitejs/vite#8219
Source for web worker: https://v3.vitejs.dev/guide/features.html#web-workers

@superrnovae
Copy link

superrnovae commented Nov 29, 2024

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.

@MPizzotti
Copy link

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

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