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.

Impossible to lock sockjs version

See original GitHub issue

Version: 7.3.2

Environment:

  • Operating system: Android
  • Browser: AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
  • Node.js: 10.15.2

I’m seeing the following in the console:

E/browser ( 2462): Console: Uncaught Error: Incompatible SockJS! Main site
uses: "1.3.0", the iframe: "1.1.4". https://cdn.jsdelivr.net/sockjs/1/sockjs.min.js:2

If I understand the flow correctly, this is what happens:

  1. on this device/browser combination, SockJS tries various transport strategies and eventually picks the iframe
  2. it requests the iframe from the server
  3. in https://github.com/sockjs/sockjs-node/blob/4c9f3009be13962b0785138ccdf527c5abe925f6/lib/iframe.js, the server generates the iframe, embedding the sockjs_url argument so the iframe knows where it has to load the library from
  4. here: https://github.com/primus/primus/blob/bfc3f3180aeebe0c45019b8ec86b260935011e52/transformers/sockjs/server.js#L43 primus does not specify a sockjs_url, so
  5. at https://github.com/sockjs/sockjs-node/blob/e2369c3d02c7e285ecbac409f3a4d0c8b72c39d3/lib/server.js#L31, sockjs picks the latest from jsdelivr as default

Unfortunately that means that sockjs client updates my happen at any time on end users’ devices, with no way for the developer to first test them.

I fixed this (perhaps simplistically) in https://github.com/sockjs/sockjs-node/blob/e2369c3d02c7e285ecbac409f3a4d0c8b72c39d3/lib/server.js#L31 by changing:

  this.service = sockjs.createServer();

Into:

  const SOCKJS_CLIENT_VERSION = require('sockjs-client/package.json').version
  this.service = sockjs.createServer({
    sockjs_url: 'https://cdn.jsdelivr.net/npm/sockjs-client@' + SOCKJS_CLIENT_VERSION + '/dist/sockjs.min.js'
  });

If that sounds like a good approach, I’ll prepare a PR.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
bardcommented, Mar 10, 2019

…and on third look, it seems that everything will go right by itself when the following change in sockjs-node gets released: https://github.com/sockjs/sockjs-node/commit/dc5a3d9ce809ed5e692bc1a5159546aa4824ee31

Currently, it’s the link https://cdn.jsdelivr.net/sockjs/1/sockjs.min.js that keeps resolving to sockjs-client 1.1.4 even when sockjs-node expects 1.3.0. The commit above changes the CDN link to https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js which correctly resolves to sockjs-client 1.3.0.

Pinging @brycekahle … any chance for a release?

0reactions
lpincacommented, May 26, 2019

Thank you @brycekahle. I’m closing as there is a workaround until a new release is cut.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trouble with sockjs or dependencies in Angular - Stack Overflow
SockJS SockJSClient initSocket (anonymous) . ... in package-lock.json the dependencia seems right "sockjs": { "version": "0.3.19", ...
Read more >
sockjs/sockjs-node: WebSocket emulation - Node.js server
Any SockJS server complying with 0.3 protocol does support a raw WebSocket url. The raw WebSocket url for the test server looks like:...
Read more >
where is sockjs-client@1.6.0: defined? : r/reactjs - Reddit
Try looking through the package lock file. ... sockjs-client@^1.5.0: version "1.5.2" resolved ... Seems impossible to get a React job.
Read more >
SockJS - Centrifugo
SockJS is a polyfill browser library which provides HTTP-based fallback transports in case when it's not possible to establish Websocket connection.
Read more >
26. WebSocket Support - Spring
This is why Spring provides fallback options that emulate the WebSocket API as close as possible based on the SockJS protocol (version 0.3.3)....
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