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

Invalid "instanceof" operand URL when using WebSocket on client #1576

Open
CPlusPatch opened this issue Feb 9, 2023 · 2 comments
Open

Invalid "instanceof" operand URL when using WebSocket on client #1576

CPlusPatch opened this issue Feb 9, 2023 · 2 comments

Comments

@CPlusPatch
Copy link
Contributor

Hello, I am using Next.js to make an app and I am trying to connect to my account using WebSocket.

Here is my code (frontend React)

export const HomeFeed = () => {
	const [posts, setPosts] = useState<Entity.Status[]>([]);

	useEffect(() => {
		const client = generator(
			"pleroma",
			"wss://fedi.cpluspatch.com",
			process.env.NEXT_PUBLIC_ACCESS_TOKEN,
		);

		const stream: WebSocketInterface = client.userSocket()

		stream.on("connect", () => {
			console.log("connect");
		});

		stream.on("parser-error", (err: Error) => {
			console.error(err);
		});
	}, []);

	return ...
};

Here is my Webpack config:

webpack: (config) => {
		config.resolve.fallback = {
			net: false,
			tls: false,
			dns: false,
			zlib: false,
			fs: false,
			stream: require.resolve('stream-browserify'),
			events: require.resolve('events'),
			buffer: require.resolve('buffer'),
			url: require.resolve('url'),
			http: require.resolve('stream-http'),
			https: require.resolve('https-browserify'),
			crypto: require.resolve('crypto-browserify'),
			querystring: require.resolve('querystring-es3'),
			os: require.resolve('os-browserify/browser'),
			assert: require.resolve('assert')
		}

		return config;
	}

The error I am getting is "TypeError: invalid 'instanceof' operand URL" at line const stream: WebSocketInterface = client.userSocket()

Here is my stack trace: https://pastebin.com/v5hkQN0Y

Am I doing something wrong?

@h3poteto
Copy link
Owner

h3poteto commented Mar 4, 2023

Hmm, I'm not sure. Your code seems good.

@CPlusPatch
Copy link
Contributor Author

This has happened several times with different projects

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

2 participants