LiveQuery Issue. Cannot read properties of undefined (reading 'socket')

Hi,

I set up my liveQuery server like this:

const port = process.env.PORT || 3001;
httpServer.listen(port, () => {
  console.log(`Server running on port ${port}.`);
});

ParseServer.createLiveQueryServer(httpServer);

And my client code like this:

  async function subscribeToTTI() {
    const query = new Parse.Query("TextToImage");
    const subscription = await query.subscribe();

    subscription.on("open", () => {
      console.log("Connected...")
    });
  }

  useEffect(() => {
    subscribeToTTI();
  }, [])

In the server logs I can see that client is connected:

info: Create new client: bae5431c-3d45-4529-be74-4fec3b03f25e

But on the client side I’m getting this error and the subscription is not working:

TypeError: Cannot read properties of undefined (reading 'socket')

Do you know what might be the reason? I run my parse server locally on port 3001, and my nextjs client side on port 3000.

Thank you

Which version are you using? See ⚠️ Parse JS SDK 3.5 Issues · Issue #1615 · parse-community/Parse-SDK-JS · GitHub

1 Like

I’m using version 3.5. Okay, I’ll roll back and write an update. Thank you for letting me know.

The issue persists on version 3.4.4. Here are my frontend dependencies:

  "dependencies": {
    "axios": "^1.1.3",
    "localstorage-slim": "^2.3.0",
    "next": "13.0.2",
    "parse": "^3.4.4",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-loading": "^2.0.3",
    "react-select": "^5.5.3",
    "sass": "^1.56.0",
    "swr": "^1.3.0"
  }

and backend:

  "dependencies": {
    "@parse/s3-files-adapter": "^1.6.2",
    "axios": "^1.1.3",
    "body-parser": "^1.20.1",
    "cors": "^2.8.5",
    "dotenv": "^16.0.3",
    "express": "^4.18.2",
    "parse-server": "^5.3.3",
    "parse-smtp-template": "^2.2.2",
    "request": "^2.88.2",
    "sharp": "^0.31.2"
  },
  "devDependencies": {
    "nodemon": "^2.0.20"
  }

I’m using node v 18.3.0.

I tried deleting the package lock and node modules but with no luck.

The problem is in these lines of code. For some reason the socket is undefined.

      this.connectPromise.then(function () {
        this.socket.send((0, _stringify.default)(subscribeRequest));
      });

parse > lib > browser > LiveQueryClient.js > line 396

Can you try fix the version to 3.5.1-alpha.2 using:

"parse": "3.5.1-alpha.2"

And then run npm install

2 Likes

Yes, it’s working on this version. Thank you so much for help.