vite-plugin-solid
vite-plugin-solid copied to clipboard
solid-js is being bundled twice in production and not in dev
In dev mode solid-js module is being dedup to ensure its only being bundled once. But when you build for production its not and thus solid-js can be bundled twice leading to side effects like createEffect not having a root because there are two solids running.
I think the solution is to always set dedup and optimizeDeps to the libraries you have listed to prevent them from being bundled twice or be able to pass in dedupe: [...nestedDeps, ...solidPkgsConfig.nestedDeps]
This is related to: https://github.com/solidjs/solid/issues/1843 and is the root cause of that issue.
I've had to add
resolve: {
dedupe: ['solid-js'],
},
To my vite config to fix the issue. I think this should be dedupe by default...
Thanks @chiefcll 🙏 I lost 1 hour on this... I think it should be at least mentioned in the docs.
Ok I have spent half a day trying to figure out my issue and it seems like maybe this is related! When I am running my unit tests with vitest, whenever I use my main vite config that has the vite-plugin-solid included, it runs my tests twice! Does this make any sense? It seems like too much of a coincidence to not be related? Any ideas on solutions / workarounds as the resolve['dedupe'] does not seem to work for vite plugins (or whatever is causing the duplication). Thanks in advance for any help or ideas!
When I am running my unit tests with
vitest, whenever I use my main vite config that has thevite-plugin-solidincluded, it runs my tests twice!
FYI see this thread for the solution to my issue mentioned above: https://github.com/solidjs/vite-plugin-solid/pull/101#issuecomment-1698495511