-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
ERR_UNKNOWN_FILE_EXTENSION
with css
inside dependency
#3862
Comments
Use |
Such an option does not exist. You mean optimizeDeps.disabled? I just tried it, same error. I also tried optimizeDeps.exclude, also changes nothing. I think this is defintely a bug in vitest because the resolution works with vite. |
https://vitest.dev/config/#deps-optimizer
This is not a bug, but a performance optimization. We cannot run all dependencies inside vite-node because your tests will be running x10 slower. If you want identical handling, use browser tests. Vitest does a lot of hacks to be performant, but we cannot handle all cases. I just want to elaborate on the idea with the optimizer (currently in the reproduction it doesn't change anything). When These files are then imported using the native Node.js mechanism (not the vite-node wrapper that is used for source code, it is very slow on large amounts of files). Unfortunately with assets ( Vitest will provide an alternative option to allow the processing of specific files without inlining them (so, they will still run in Node.js, and not in slow vite-node): deps: {
optimizer: {
web: {
transformAssets?: boolean
transformCss?: boolean
transformGlobPattern?: string[]
}
}
} |
So what would you put into deps: {
optimizer: {
web: {
disabled: true,
},
},
}, Is it possible to fix without specifying the name of the dependency?
I don't really mind slower performance if the outcome is correct and works resolves like vite. Ideally a CSS import would alter |
There is no "disable" option in the optimizer. It's called
I do mind it :) As I said before, you can still use |
Would you mind posting a full config for the repro that works? The vitest docs link to vite's import {defineConfig} from "vitest/config";
export default defineConfig({
test: {
environment: "jsdom",
deps: {
optimizer: {
web: {
disabled: true,
},
},
},
},
}); |
Generally, I do think removing this implicit CSS import and moving it to an explicit |
There is an open issue: #3524
You are correct that currently it will not work because we always inline optimized dependencies which is a bug, but the working config would be: {
test: {
css: {
include: /.+/,
},
server: {
deps: {
inline: [
/vitest-css-test-module/,
]
}
}
},
} |
Okay, feel free to close unless you want to keep it open for the mentioned bug. I will definitely remove these CSS imports as I don't feel like relying on such advanced/unstable config options is a good idea. I do wonder one thing thought: What if the module would export a |
Yes, you need to add those files to Usually, Vite plugins add those dependencies manually to
Vitest will start processing assets and CSS in |
Describe the bug
When a npm dependency imports CSS, vitest's resolution fails with node error
ERR_UNKNOWN_FILE_EXTENSION
, even with thecss
option is enabled. The same works fine when the imported CSS file is first-party, so I think it's an error in vitest's module resolution. vite is able to build this fine, but vitest fails.Previous suggestions to this problem were to use
deps.inline
, but as this has now been deprecated, I'm looking for better solutions which ideally do not involve whitelisting the dependencies that have CSS imports.Reproduction
Repo: https://github.com/silverwind/vitest-css.
Dependency vitest-css-test-module is published to npm from the subdirectory.
Will fail with
System Info
Used Package Manager
npm
Validations
The text was updated successfully, but these errors were encountered: