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

Using vite-plugin-solid with vitest workspaces prevents solid-js from resolving correctly #102

Open
jfrere opened this issue Jun 23, 2023 · 3 comments

Comments

@jfrere
Copy link

jfrere commented Jun 23, 2023

Description

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 and vite-plugin-solid, the solid-js resolution system fails to work properly, and functions like createStore() throw errors.

Reproduction

https://stackblitz.com/edit/solidjs-templates-4usktg?file=README.md&view=editor

The problem can be reproduced by running npm run test-all in the console. This runs a test that just calls createStore.

Running npm run test-fe-only runs vitest in the frontend/ package, which bypasses Vitest's workspaces system, everything works again.

Running npm run test-all-no-plugin runs vitest the same as in test-all, but with the vite-plugin-solid plugin disabled. Again, this works as expected.

Error/Investigation

The error returned is:

TypeError: Cannot read properties of undefined (reading 'registerGraph')
 ❯ Module.createStore node_modules/solid-js/store/dist/dev.js:213:9
 ❯ packages/frontend/src/test.spec.ts:6:36

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.

Thanks for any help!

@link2xt
Copy link

link2xt commented 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
Copy link

GitMurf commented Aug 30, 2023

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.

See here: #112 (comment)

@MrJohz
Copy link

MrJohz commented 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: true to my vite configuration, and that worked fine, but there are some other suggestions in the linked discussion.

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

4 participants