With React project set up with Vite and run tests with Vitest v2.1.1, we might see the following issue with CSS files:
TypeError: Unknown file extension
.css
for/path/to/css/file
How can we resolve it?
With React project set up with Vite and run tests with Vitest v2.1.1, we might see the following issue with CSS files:
TypeError: Unknown file extension
.css
for/path/to/css/file
How can we resolve it?
2
Answers
The solution is to set the pool option to use
vmThreads
orvmForks
, like this:With this option, the following option
deps.web.transformCss
will be set to true by default, which will resolve the problem.As discussed in issue vitest-dev/vitest #3862, the solution to the problem is setting the
deps.web.transformCss
parameter totrue
.@MinhTC gave a similar answer but did not provide an explanation. I would attach this alongside it.
The relevant part of the deps.web.transformCss section from the Vitest documentation reads as follows:
Although the setting is
true
by default, which would suggest that the error message mentioned in the question should not occur, the warning in the documentation clearly explains that the setting will only work with thepool: "vmThreads"
orpool: "vmForks"
configuration, what mentioned by @MinhTC.Alternative solution
Although the file was missing from the question (which could possibly belong to a external package), and only need to inform Vitest to use the external files with the
server.deps.inline
.