I was working on migration my application from CRA to Vite.
Project is using React, Tailwind, SCSS, TS and Vite. After migration application works well with all Tailwind styles locally. It is also possible to build the application locally. The problem is with building application in the CI/CD process.
Old TailwindCSS configuration:
- postcss.config.js
- tailwind.config.js
- tailwind.css
New TailwindCSS configuration for Vite which was applied to the project - https://tailwindcss.com/docs/installation/using-vite 1. package.json
2. vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
import tailwindcss from '@tailwindcss/vite';
import { configDefaults } from 'vitest/config';
// https://vite.dev/config/
export default defineConfig({
plugins: [react(), tailwindcss()],
resolve: {
alias: {
src: path.resolve(__dirname, './src'),
},
},
server: {
port: 3000,
},
test: {
globals: true,
environment: 'jsdom',
exclude: [...configDefaults.exclude, 'e2e/*'],
coverage: {
provider: 'v8',
reporter: ['text', 'json', 'html', 'lcov'],
reportsDirectory: 'coverage',
reportOnFailure: true,
},
},
});
3. tailwind.css
@import 'tailwindcss';
Problem to solve
vite v6.3.5 building for development...
transforming...
✓ 73 modules transformed.
✗ Build failed in 1.17s
error during build:
[vite:css] Failed to load PostCSS config (searchPath: /home/vsts/work/1/s): [ReferenceError] module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/vsts/work/1/s/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
ReferenceError: module is not defined in ES module scope
This file is being treated as an ES module because it has a '.js' file extension and '/home/vsts/work/1/s/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
at file:///home/vsts/work/1/s/postcss.config.js?t=1747035485705:1:1
at ModuleJob.run (node:internal/modules/esm/module_job:263:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:540:24)
at async req$3 (file:///home/vsts/work/1/s/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:11658:13)
at async Object.search (file:///home/vsts/work/1/s/node_modules/vite/dist/node/chunks/dep-DBxKXgDP.js:11400:23)
file: /home/vsts/work/1/s/src/styles/index.scss
For my internal styles I am using index.scss file but for tailwind styles I've created tailwind.css file. Both of them are imported to the same parent component. Previously I had that postCss config file but now I don't have it so I don't know why this error occurs. Any ideas?
I checked what happens in the building process and I found something like:


index.scss- Just a note here that TailwindCSS v4 officially does not support preprocessors, so any issues arising from this will not be addressed. See more: Deprecated: Sass, Less and Stylus preprocessors support--debugand I see that still I have some dependencies:vite:config css: { vite:config transformer: 'postcss', vite:config preprocessorMaxWorkers: 0, vite:config devSourcemap: false vite:config }, vite:config json: { namedExports: true, stringify: 'auto' }, vite:config builder: undefined,