Errors updating to 3.0.0/3.0.1 with Svelte / Vite
Bug Report
Using Svelte / Vite and upgrading from v2 to v3, I get a strange import error.
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?
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.
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?
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.
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.
I'm also having this issue. Have you managed to find a fix? Including PerspectiveEsbuildPlugin in vite plugins did not help.
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
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.
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.
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
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.
Fetching wasm using URL relative to
import.meta.urland passing the response toload_wasm_stage_0seems to work in vite, and should theoretically be compatible with other bundlers. As for the worker, instantiating it usingnew 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
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.