Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Websocket issue: WebSocket connection to 'ws://localhost:8765/gun' failed: #1278

Closed
mertdeveci5 opened this issue Aug 31, 2022 · 4 comments
Closed

Comments

@mertdeveci5
Copy link

Everytime I run gun.js in the frontend of my application, I get the following error in the console of the browser:

WebSocket connection to 'ws://localhost:8765/gun' failed:

The link changes to various different URLs and there is a new log with a new link every several seconds. Does anyone know the reason for this? Or do I have the incorrect configurations? Please see below for reference:

user.js

import Gun from "gun";
import "gun/sea";
import "gun/axe";
import { useAccount } from "wagmi";
import { createContext, useState } from "react";

export const db = Gun();

export const user = db.user().recall({ sessionStorage: true });

server.js

const express = require("express");
const app = express();
const Gun = require("gun");
const port = 5000;

app.use(Gun.serve);

const server = app.listen(port, () => {
  console.log(`Server running on port ${port}🔥`);
});

Gun({ web: server });
@soulofmischief
Copy link

soulofmischief commented Aug 31, 2022

@mertdeveci5 browsers need to import gun using import Gun from 'gun/gun', not import Gun from 'gun', to avoid running Node-specific code. More information here

Does this fix your issue?

@mertdeveci5
Copy link
Author

This did not fix it but I guessed I fixed it by adding the localhost:8765 as a peer in the frontend. Nevertheless, the websocket error keeps popping up from time to time

@soulofmischief
Copy link

This did not fix it but I guessed I fixed it by adding the localhost:8765 as a peer in the frontend. Nevertheless, the websocket error keeps popping up from time to time

ah yeah, I didn't even notice you didn't provide a URI for the relay. Without that, the apps don't know about each other. Are you using <address>/gun?

@saiksaif
Copy link

This did not fix it but I guessed I fixed it by adding the localhost:8765 as a peer in the frontend. Nevertheless, the websocket error keeps popping up from time to time

Hi, were you able to solve that? I'm facing the same issue in my sveltekit project and have no idea how to fix this can you help?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants