'WebSocket is not supported by this browser.' in a node environment
See original GitHub issueDo you want to request a feature or report a bug? Report a bug
What is the current behavior?
(node:30502) UnhandledPromiseRejectionWarning: Error: AMQJS0010E WebSocket is not supported by this browser.
at new ClientImpl (/home/brandon/src/matrix-runner/node_modules/aws-appsync/lib/vendor/paho-mqtt.js:771:11)
at new Client (/home/brandon/src/matrix-runner/node_modules/aws-appsync/lib/vendor/paho-mqtt.js:1782:17)
at SubscriptionHandshakeLink.<anonymous> (/home/brandon/src/matrix-runner/node_modules/aws-appsync/lib/link/subscription-handshake-link.js:170:34)
at step (/home/brandon/src/matrix-runner/node_modules/aws-appsync/lib/link/subscription-handshake-link.js:56:23)
at Object.next (/home/brandon/src/matrix-runner/node_modules/aws-appsync/lib/link/subscription-handshake-link.js:37:53)
at /home/brandon/src/matrix-runner/node_modules/aws-appsync/lib/link/subscription-handshake-link.js:31:71
at new Promise (<anonymous>)
at __awaiter (/home/brandon/src/matrix-runner/node_modules/aws-appsync/lib/link/subscription-handshake-link.js:27:12)
at SubscriptionHandshakeLink.connectNewClient (/home/brandon/src/matrix-runner/node_modules/aws-appsync/lib/link/subscription-handshake-link.js:163:16)
at /home/brandon/src/matrix-runner/node_modules/aws-appsync/lib/link/subscription-handshake-link.js:159:75
(node:30502) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 2)
(node:30502) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
function graphqlSubscribe(accessToken) {
// Set up Apollo client
const client = new AWSAppSyncClient({
url: url,
region: region,
auth: {
type: type,
jwtToken: accessToken,
}
});
const gql = require('graphql-tag');
// Set up a subscription query
const subquery = gql(`subscription OnCreateBuild {
onCreateBuild {
id
buildNumber
}
}`);
client.hydrated().then(function (client) {
//Now run a query
// client.query({ query: query })
// //client.query({ query: query, fetchPolicy: 'network-only' }) //Uncomment for AWS Lambda
// .then(function logData(data) {
// console.log('results of query: ', data);
// })
// .catch(console.error);
//Now subscribe to results
const observable = client.subscribe({ query: subquery });
const realtimeResults = function realtimeResults(data) {
console.log('realtime data: ', data);
};
observable.subscribe({
next: realtimeResults,
complete: console.log,
error: console.log,
});
});
}
What is the expected behavior? No errors
Which versions and which environment (browser, react-native, nodejs) / OS are affected by this issue? Did this work in previous versions? nodejs v8.12.0, unknown if it works in another version
Issue Analytics
- State:
- Created 5 years ago
- Reactions:3
- Comments:7 (2 by maintainers)
Top Results From Across the Web
websocket problem: cannot connect to node.js server
When I try to add socket.io.js into my client, I get an error that the client can't find "require". I looked at the...
Read more >WebSocket - Wikipedia
WebSocket is a computer communications protocol, providing full-duplex communication ... Most browsers support the protocol, including Google Chrome, Firefox, ...
Read more >How To Create a Real-Time App with Socket.IO, Angular, and ...
A modern web browser that supports WebSocket. This tutorial was originally written in an environment consisting of Node.js v8.11.4, ...
Read more >NodeJS support for y-websocket? - Yjs Community
... take to make y-websocket support the nodejs runtime environment. ... in node, it fails with “ReferenceError: window is not defined”, ...
Read more >Why the Hell Would I Use Node.js? A Case-by-case Tutorial
Node.js can solve I/O scaling, but was not created to compute scaling ... The applications would run on the open web stack backed...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @blbradley
Node environments don’t have a
Websocket
implementation, one thing you can do is:npm i ws@^3.3.1
and then in your file do a
Hi @blbradley
It could be possible but I personally don’t think it would be a good idea, since consuming code might already be providing a different polyfill.
Totally agree, I’ve tagged this issue as documentation to take care of that
Yeah, the docs could be clearer about this, though they have these lines:
NOTE Please note that you need
ws
versions3.x
or4.x
(NOT5.x
since it has some issues connecting to the mqtt/ws endpoints AppSync uses)