You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Using vite-plugin-solid with vitest workspaces prevents solid-js from resolving correctly #102
Vitest has a workspaces feature, where vitest can be made aware of different sub-projects, and run the tests for each of these workspaces (based on their individual configuration) together.
However, when using Vitest workspaces andvite-plugin-solid, the solid-js resolution system fails to work properly, and functions like createStore() throw errors.
This is because in dev-mode, the createStore tries to access the DEV object exported by solid-js. This DEV object is only available if solid-js is running in dev mode (in production, a different file is used which sets DEV to undefined).
However, for some reason, when Vite/NodeJS/Vitest/? tries to resolve the import solid-js from node_modules/solid-js/store/dist/dev.js, it instead imports the production version of solid-js, which obviously doesn't have the correct exported DEV object, and so an error is thrown.
I'm creating this issue here, because the error only occurs if vite-plugin-solid is installed, but I'm not entirely sure what this plugin is doing that makes things behave weirdly here. There isn't any JSX to process, so I would have through the plugin is essentially a no-op.
I have reported the same issue: #104. But in my case the tests pass on GitHub Actions and for other developers who run Node.js 16. Your example runs v16.20.0 but still fails.
I have been running into really odd behavior with vitest and the solid vite plugin and am curious if you all think this is related? See details below, but basically whenever I have the plugin enabled, all my unit tests (whether using solid or not) run twice! It is super odd and frustrating that I cannot get to the bottom of it.
Hi, I ran into this same problem again, and ended up asking about it on the Vitest project: vitest-dev/vitest#6537 It looks like there is a known bug in Vitest affecting this (vitest-dev/vitest#5301). This plugin may be able to work around this by changing configuration settings.
I was able to add test.server.deps.inline: true to my vite configuration, and that worked fine, but there are some other suggestions in the linked discussion.
@birkskyum Today I ran into this issue as well, but it was a multitude of related transform bugs, React ref not found, loading the server version of solidjs router code instead of the web or dev one in tests. even after I was able to fix it when I try to setup the configs for projects with vitest I ran into it again as well.
This is my env, running in bun 1.3.10
solid-js: 1.9.11
@solidjs/router: 0.15.4
@solidjs/testing-library: 0.8.10
vite-plugin-solid: 2.11.10
babel-preset-solid (transitive): 1.9.10
solid-refresh (transitive): 0.6.3
What fix it for now its @MrJohz mentioned, fix the transformation issues and now the test run stable.
test.server.deps.inline: true
im adding my config below in case it helps anyone that runs into this in the future.
importpathfrom'node:path';import{defineConfig}from'vitest/config';importsolidfrom'vite-plugin-solid';exportdefaultdefineConfig({resolve: {alias: {'#src': path.resolve(__dirname,'src'),'#test': path.resolve(__dirname,'test'),}},test: {projects: [{extends: true,test: {name: 'app',dir: 'test',exclude: ['web/**'],}},{extends: true,plugins: [solid()],resolve: {conditions: ['developement','browser'],},test: {name: 'web',dir: 'test/web',environment: 'jsdom',server: {deps: {// https://github.com/solidjs/vite-plugin-solid/issues/102#issuecomment-2363242031// must have to fix test environment issuesinline: true,},}}}]}});
Activity
link2xt commentedon Jul 14, 2023
I have reported the same issue: #104. But in my case the tests pass on GitHub Actions and for other developers who run Node.js 16. Your example runs v16.20.0 but still fails.
GitMurf commentedon Aug 30, 2023
I have been running into really odd behavior with
vitestand the solid vite plugin and am curious if you all think this is related? See details below, but basically whenever I have the plugin enabled, all my unit tests (whether using solid or not) run twice! It is super odd and frustrating that I cannot get to the bottom of it.See here: #112 (comment)
MrJohz commentedon Sep 20, 2024
Hi, I ran into this same problem again, and ended up asking about it on the Vitest project: vitest-dev/vitest#6537 It looks like there is a known bug in Vitest affecting this (vitest-dev/vitest#5301). This plugin may be able to work around this by changing configuration settings.
I was able to add
test.server.deps.inline: trueto my vite configuration, and that worked fine, but there are some other suggestions in the linked discussion.birkskyum commentedon Feb 27, 2025
We've updated some thing in the plugin that might affect this issue.
Is this still a problem with 2.11.6?
juanka881 commentedon Mar 3, 2026
@birkskyum Today I ran into this issue as well, but it was a multitude of related transform bugs, React ref not found, loading the server version of solidjs router code instead of the web or dev one in tests. even after I was able to fix it when I try to setup the configs for projects with vitest I ran into it again as well.
This is my env, running in bun 1.3.10
solid-js: 1.9.11
@solidjs/router: 0.15.4
@solidjs/testing-library: 0.8.10
vite-plugin-solid: 2.11.10
babel-preset-solid (transitive): 1.9.10
solid-refresh (transitive): 0.6.3
What fix it for now its @MrJohz mentioned, fix the transformation issues and now the test run stable.
im adding my config below in case it helps anyone that runs into this in the future.