withastro/astro

Cannot run vitest using `examples/with-vitest` with astro 5.0.3

maiwald opened this issue · 5 comments

Astro Info

Astro                    v5.0.3
Node                     v18.17.1
System                   macOS (arm64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Hi there!

Running npm run test run fails with Unknown Error: [object object]. I also ran this using node v20.18.0 but the result is the same.
Screenshot 2024-12-06 at 09 24 09

The code is using the Stackblitz link found on the example README.md

There is an issue that is probably related: #12384

What's the expected result?

I would expect the tests to run. :)

Link to Minimal Reproducible Example

https://stackblitz.com/github/withastro/astro/tree/latest/examples/with-vitest?file=README.md

Participation

  • I am willing to submit a pull request for this issue.

I can confirm the issue and yes this is related to the closed one. Vitest has reverted its support for Vite 6 in 2.1.7 so it seems there are some conflicts...

I tried to use "vitest": "2.1.6" instead of "vitest": "^2.1.6" but it doesn't seem to work... What worked for me, as suggested by HiDeoo:

"pnpm": {
    "overrides": {
      "@vitest/coverage-v8>vite": "6.0.2",
      "@vitest/mocker>vite": "6.0.2",
      "vitest>vite": "6.0.2"
    }
}

If you use npm, you can add the following lines to package.json (tested with the vitest example and it works for me):

"overrides": {
    "vite": "6.0.2"
}

However, I don't know if we should update the example in the meantime since this should be temporary... According to a Vitest issue (vitest-dev/vitest#6992), Vite 6 will only be supported from Vitest 3 expected in January.

I can confirm that the npm override worked for me. Thanks!

Had the same problem. Ii'm using yarn, so solved it by setting resolutions in package.json like this:

"resolutions": {
    "vite": "6.0.3",
}

The workaround works for me as well! 👍

However, I don't know if we should update the example in the meantime since this should be temporary... According to a Vitest issue (vitest-dev/vitest#6992), Vite 6 will only be supported from Vitest 3 expected in January.

I understand. What would you say to adding a note to the migration page? The workaround might be a little hard to find for others in an issue.

I'll keep this open to make it easier for people to find, but this is an issue which needs to be fixed upstream in Vitest. In the meantime, the overrides are the best approach.