gradio icon indicating copy to clipboard operation
gradio copied to clipboard

TypeError: Cannot set property WebSocket of #<Object> which has only a getter / Gradio App not working in NextJS

Open cantonalex opened this issue 2 years ago • 4 comments

Describe the bug

unsure why this was closed I still get the same issue on node 20 and nextjs 14 #5583

Have you searched existing issues? 🔎

  • [X] I have searched and found no existing issues

Reproduction

latest nextjs version

Screenshot

No response

Logs

No response

System Info

node 20 nextjs 14 mac os sonoma

Severity

Blocking usage of gradio

cantonalex avatar Nov 23 '23 09:11 cantonalex

@pngwn

cantonalex avatar Nov 23 '23 09:11 cantonalex

No need to ping maintainers. We can see the issue and will get to it as soon as we can.

pngwn avatar Nov 23 '23 20:11 pngwn

I finally found a suitable solution. We should not use the gradio client on the server side of Next.js, but instead use it on the client side. Also, by adding the following configuration to next.config.js, I managed to solve the problem:

const {webpack} = require("next/dist/compiled/webpack/webpack");
/** @type {import('next').NextConfig} */
const nextConfig = {
    // output: 'export',
    // Optional: Add a trailing slash to all paths `/about` -> `/about/`
    // trailingSlash: true,
    // Optional: Change the output directory `out` -> `dist`
    // distDir: 'dist',
    webpack: (config, {isServer}) => {
        if (!isServer) {
            config.resolve = {
                ...config.resolve,
                fallback: {
                    // fixes proxy-agent dependencies
                    net: false,
                    dns: false,
                    tls: false,
                    assert: false,
                    // fixes next-i18next dependencies
                    path: false,
                    fs: false,
                    // fixes mapbox dependencies
                    events: false,
                    // fixes sentry dependencies
                    process: false
                }
            };
        }
        config.plugins.push(new webpack.NormalModuleReplacementPlugin(/node:/, (resource) => {
            resource.request = resource.request.replace(/^node:/, "");
        }))
        return config
    },
    experimental: {appDir: true}
};
module.exports = nextConfig

I hope this comment will help those using Next.js.

SDLi416 avatar Jan 09 '24 01:01 SDLi416

+1 to this issue, this is a huge blocker for me as my software depends on the gradio client to interface with my private spaces. The issue is somehow related to assigning global.WebSocket = ws.WebSocket 🤷

@pngwn Do you have an estimate on when this will be investigated? This has been an issue since September 17th.

jakiestfu avatar Feb 20 '24 21:02 jakiestfu

Duplicate of #5583

pngwn avatar Apr 11 '24 11:04 pngwn