-
-
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
"Can't find stylesheet to import" when using --threads=false #1230
Comments
I can confirm I am also encountering this issue on the latest version of vitest with threading turned off:
This is imported into my Versions:
|
I'm getting this too, but doesn't matter if I'm using threads=false or not.
I have in my main config this
And
I"ve tried a few combinations of filenames with and without aliases but to no avail. If I change all imports to their absolute paths on my filesystem, eg:
Then it starts working, so it's not resolving the aliases properly for SCSS as far as I can see, while in Vite itself it's all working fine. |
I have the same issue. I have found that the actual error occurs even though the resolution may have worked properly.
<style lang="scss" scoped>
@import "../../../variables";
// ...
export default defineConfig({
// ...
resolve: {
alias: [
{
find: "../../../variables",
replacement: "/Users/user/git/project/_variables.scss",
},
],
},
})
It means, that even after resolving to absolute path manually the resolved path seems to not be consumed properly. |
The only real place I get this being an issue is in the So to circumvent the issue for now I'm doing this to basically ensure that it's an absolute path. I'm basically duplicating the alias and it seems to be working. Within the SCSS files in the repo that a test they are using relative paths. {
resolve: {
{
find: /^@\//,
replacement: `${path.resolve(__dirname, 'src')}/`,
},
},
// ...
css: {
preprocessorOptions: {
scss: {
additionalData: `
@use "sass:math";
@import "${path.resolve(__dirname, 'src')}/styles/_variables.scss";
@import "${path.resolve(__dirname, 'src')}/styles/_mixins.scss";
`,
},
},
},
} |
|
Since it works with absolute routes, I ended up creating an alias for my variables file Project info
vitest.config.tsexport default defineConfig({
plugins: [react()],
test: {
environment: 'jsdom',
},
resolve: {
alias: [
{
find: 'variables',
replacement: `${path.resolve(__dirname)}/styles/variables.scss`
}
]
}
}) {file}.scss
It is working for me right now but it is not an optimal solution |
Ok it seems that relative import are broken. It happens with or without If the main scss files import other files, then the paths have to be absolute, else it will return the error My workaround (for one file): import { defineNuxtConfig } from 'nuxt'
import { resolve } from 'path'
const r = (p: string) => resolve(__dirname, p)
export default defineNuxtConfig({
vite: {
css: {
preprocessorOptions: {
scss: { additionalData: `@use "${r('assets/scss/global.scss')}";` },
},
}
}
}) If there is multiple files, my workaround becomes: css: {
preprocessorOptions: {
scss: { additionalData: `@use "${r('assets/scss/global.scss')}";@use "${r('assets/scss/reset.scss')}";@use "${r('assets/scss/typography.scss')}";@use "${r('assets/scss/fonts.scss')}";@use "${r('assets/scss/spacing.scss')}";@use "${r('assets/scss/dripicons.scss')}";@use "${r('assets/scss/colors.scss')}"; @use "${r('assets/scss/utils/layout.scss')}"; @use "${r('assets/scss/utils/overflow.scss')}"; ` },
},
} Basically chaining the |
None of the above suggestions seem to be working for me const resolve = (filePath: string) => {
return path.resolve(__dirname, filePath);
}; css: {
preprocessorOptions: {
scss: {
additionalData: [
// Shared global scss utilities.
`@import "${resolve('src/scss/00-base/index.scss')}";`,
'',
].join('\n'),
},
},
},
test: {
threads: false,
} |
The workaround I got to behave was: test: {
minThreads: 0,
maxThreads: 1,
} This seems silly since this is effectively doing the same thing? 🤔 |
Describe the bug
"vitest run" works fine, tests pass
"vitest run --threads=false" errors out with "can't find stylesheet to import"
in my repro, styles.scss is imported into App.tsx, and it in turn imports a stylesheet called "colors.scss"
I was only using threads=false to try to get around a Node issue in my CI build, but it doesn't work.
Reproduction
https://github.com/oneillsp96/vitest-error-2
System Info
Used Package Manager
yarn
Validations
The text was updated successfully, but these errors were encountered: