1

vitest.config.js:

import { defineConfig, mergeConfig } from 'vitest/config'

import viteConfig from './vite.config'

export default mergeConfig(
    viteConfig,
    defineConfig({
        test: {
            globals: true,
            environment: 'jsdom',
            setupFiles: './vitest.setup.ts',
            css: {
                preprocessorOptions: {
                    scss: {
                        api: 'modern-compiler',
                    },
                },
            },
        },
    }),
)

vite.config.ts

import react from '@vitejs/plugin-react'
import * as path from 'node:path'
import { defineConfig } from 'vite'
import dynamicImport from 'vite-plugin-dynamic-import'

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [react(), dynamicImport()],
    resolve: {
        alias: {
            app: path.resolve(__dirname, './src', 'app'),
            pages: path.resolve(__dirname, './src', 'pages'),
            widgets: path.resolve(__dirname, './src', 'widgets'),
            features: path.resolve(__dirname, './src', 'features'),
            entities: path.resolve(__dirname, './src', 'entities'),
            shared: path.resolve(__dirname, './src', 'shared'),
        },
    },
    build: {
        rollupOptions: {
            output: {
                entryFileNames: `assets/[name].[hash].js`,
                chunkFileNames: `assets/[name].[hash].js`,
                assetFileNames: `assets/[name].[hash].[ext]`,
            },
        },
    },
    css: {
        preprocessorOptions: {
            scss: {
                api: 'modern-compiler', // or "modern"
            },
        },
    },
})

Tests is completed, but many warnings in console. I dont can founded resolve this. Please help me

screen errors in console

I've tried it in different ways change config, write gpt, read docs vite and vitest, nothing not help. Please help me Error exactly when run tests, at run dev error nothing

7
  • 2
    The Warning is telling you that the API that you are using is legacy and you need to either ignore the warning and pin to this version of the library or you need to upgrade to the new API. If go to the link provided in the error it tells you how to migrate to the new API. Commented Sep 26, 2024 at 19:36
  • 1
    Have you read the docs in the More Info section of the warning? Commented Sep 26, 2024 at 19:37
  • What is this "modern-compiler" option and why do you use it? Commented Sep 26, 2024 at 20:23
  • this option work in vite.config.ts, but not working in vitest.config.ts. I don't know how to force he work Commented Sep 26, 2024 at 23:03
  • preprocessorOptions - used in vitest.config.ts because I've tried it - it option work only vite.config.ts Commented Sep 26, 2024 at 23:10

1 Answer 1

-1

Finded resolve. deleted vite vitest sass, again install. And vite config updated:

export default defineConfig({
    css: {
        preprocessorOptions: {
            scss: {
                api: 'modern',
            },
        },
    },
    test: {
        globals: true,
        environment: 'jsdom',
        setupFiles: './vitest.setup.ts',
    },
})

vitest config deleted

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.