question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Websocket is undefined

See original GitHub issue

Hi, i have a problem when testing my component using mocha & chai, it says:

ReferenceError: WebSocket is not defined
    at module.exports.r.open (/Users/bcw-001/dev/sofia_fe_react/node_modules/sockette/src/index.js:25:32)
    at new module.exports (/Users/bcw-001/dev/sofia_fe_react/node_modules/sockette/src/index.js:48:7)

i use mock-websocket. anyone know what did i miss?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
lukeedcommented, May 21, 2018

No problem~!

You shouldn’t modify any node_modules/** code – all your changes will be immediately lost anytime you install another dependency or if/when a coworker tries to replicate your setup.

Instead, you should do this in your testing setup file, or at the top of test files (repetitive):

// test/setup.js
global.WebSocket = require('ws');
1reaction
lukeedcommented, Mar 14, 2019

Hey @tinchoz49 👋

No I would not, sorry. It would be meaningless to Sockette. You should simply do this instead:

global.WebSocket = require('ws');

This would only be set in your Node.js environment, leaving window.WebSocket intact for your browser bundle(s). If that’s not the case, then you will need to take a closer look at your build config because you should never have server code/deps in your front-end bundles. I can maybe help with this part if you have questions or issues.

The above will give you full support 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

JavaScript - ReferenceError: WebSocket is not defined
It seems like @stomp/stompjs is not the only package with a missing dependency on Websocket. In my case it was fast-xml-parser (or one...
Read more >
ReferenceError: WebSocket is not defined · Issue #11 - GitHub
I am getting following error while using this library on nodejs, I am new to this can help me to resolve this. ReferenceError:...
Read more >
node_modules/lib0/websocket.js:25:23 - Yjs Community
I'm having this issue: (base) raphy@pc:~/y-webrtc-playing$ node ./bin/server.js Signaling server running on localhost: 5555 (base) ...
Read more >
WebSocket.send() - Web APIs - MDN Web Docs - Mozilla
The WebSocket.send() method enqueues the specified data to be transmitted to the server over the WebSocket ... None ( undefined ).
Read more >
Websocket data undefined outside onmessage block
I have a variable called data and I initialize it with the json from the websocket. It is displayed in the console inside...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found