Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build is not working in react using vite bundler

enter image description here

I use web-pack before and wanted to change it to vite I copied all the file from the web-pack version to the vite version when I issue yarn dev it work but we I build it and run the build with serve dist it give me this error on the browser and it won't render any thing

like image 654
Revan99 Avatar asked Oct 25 '25 05:10

Revan99


2 Answers

You need to use this config, (take a look at @vitejs/plugin-react which you probably need to install)

vite.config.js:

import react from "@vitejs/plugin-react";
import { defineConfig } from "vite";

export default ({ mode }) => {
  return defineConfig({
    plugins: [
      react(),
    ],
  });
};

The thing is that vite does not import React by default into jsx components, so you need to do it manually in every component or use this plugin.

like image 94
valerii15298 Avatar answered Oct 27 '25 18:10

valerii15298


the problem was with a react library called react-custom-scrollbars

like image 32
Revan99 Avatar answered Oct 27 '25 19:10

Revan99



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!