vite-plugin-solid icon indicating copy to clipboard operation
vite-plugin-solid copied to clipboard

solid-js is being bundled twice in production and not in dev

Open chiefcll opened this issue 2 years ago • 4 comments

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.

chiefcll avatar Aug 06 '23 22:08 chiefcll

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...

chiefcll avatar Aug 08 '23 17:08 chiefcll

Thanks @chiefcll 🙏 I lost 1 hour on this... I think it should be at least mentioned in the docs.

ngryman avatar Aug 23 '23 07:08 ngryman

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!

image

GitMurf avatar Aug 30 '23 04:08 GitMurf

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!

FYI see this thread for the solution to my issue mentioned above: https://github.com/solidjs/vite-plugin-solid/pull/101#issuecomment-1698495511

GitMurf avatar Sep 12 '23 07:09 GitMurf