chatengine-io / react-chat-engine-advanced

Chat Engine's react components done the right way...
MIT License
18 stars 11 forks source link

Uncaught ReferenceError: require is not defined #204

Open DerYumin opened 1 year ago

DerYumin commented 1 year ago

Hello chatengine.io Team,

I have an issue with the production of my build. When I run locally with "npm run dev", there is no problem with my client and Chat. But when I deployed a production build on vercel, I got following Error:

Uncaught ReferenceError: require is not defined at index-46340fac.js:156:35877 with the following code there:

require("websocket").w3cwebsocket;

specialobyno commented 1 year ago

I am encountering exactly same issues now. Have anyone been able to find solution to this?

darshanhande11 commented 1 year ago

@alamorre I am also encountering this very issue. "npm run dev" command works fine but when trying to deploy a production build on Vercel or Netlify (I tried both). This require("websocket").w3cwebsocket error is thrown. Is there any fix for this?

granam180 commented 1 year ago

Same here as well. Runs on dev fine (desktop version at least), but getting "require is not defined" when deploying to Vercel. Even tried to redefine the build structure in vite.config.js and no luck.

Sealproton commented 1 year ago

Im also get problem after deployed on render. Its work on my local with npm run dev but it crash in production with beautiful red star on require("websocket").w3cwebsocket which help nothing. TT

mridul-spense commented 11 months ago

Same for me as well

HelenGezahegn commented 11 months ago

If you're using vite, I was getting the same exact issue too until I added this to my vite.config.js file.

 commonjsOptions: {
      transformMixedEsModules: true 

This is my config file now:

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

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: [{ find: "@", replacement: path.resolve(__dirname, "src") }]
  },
  // Fix large chunks issue due to node_modules
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (id.includes("node_modules")) {
            return id
              .toString()
              .split("node_modules/")[1]
              .split("/")[0]
              .toString();
          }
        }
      }
    },
    commonjsOptions: {
      transformMixedEsModules: true
    }
  }
});
khaphannm commented 7 months ago

same here