I deleted the folder node_modules and I downgraded my vite dependency to 5.0 in package.json and package-lock.json and then run npm install && npm run build and it worked.