An error occurred in the console after site was deployed

Hi dear Netlify support
I made a react project with Vite, which runs correctly on the local host and there is no problem, but when I take the build from the project and want to deploy it on Netlify, I get an error in the console (require is not defined), and the project does not run. This error is related to the JavaScript file that was compiled by build and Vite cannot read the require method. The reason for running on localhost is that localhost runs the project directly from the files itself, not from the build folder. I know maybe this question has nothing to do with your field of duties, but please help me because I went through many ways and it didn’t work. If I create the project with “create react app” and take the build and run it on Netlify, there is no problem, but I want to do this with Vite.
my project name “javadbahrami-reactmessenger”

Sincerely,
Javad Bahrami

@javadevbh You can test the build output of your Vite based project locally by running your Vite build, then npx serve -s dist

The following is in your code and won’t run since browsers don’t have require:

image

The package that you’re working with mostly concerns itself with Node, and I couldn’t find any decent explanation in their documentation of how it’s intended to be used in the browser “as is”.

It’s possible that on the client side you’re supposed to use the Websockets API directly:

Note: Since Netlify doesn’t provide runtime node.js hosting, you won’t be able to host a “socket server” file and if doing that, would need to host it on another service.

1 Like

Thank you for your response.
It was helpful.