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.

Cannot call addListener on the client service connection

See original GitHub issue

Steps to reproduce

Listen to events like this:

app.service('myservice').watch({ listStrategy: 'smart' })
        .find({ query })
        .subscribe(response => { ... })

Expected behavior

No error is raised, the same code worked fine with Feathers v3.

Actual behavior

The following error is raised with either Feathers v4 or v5: image

I’ve tried to dig into what is going on but I do not really understand the code fully. As far as I understand feathers services implement this mixin. The transport abstraction expects that the underlying connection also implements a similar interface. But as far as I can see, the connection object, which is a Socket for socket.io, implements a slightly different interface. For instance if I debug our app, I can see that the connection object has a addEventListener method but not a addListener method as expected. Could it be linked to a change in interface within socket.io ?

System configuration

NodeJS version 16, Webpack 5, Feathers v4 or v5

"@feathersjs/client": "^5.0.0-pre.22"
"feathers-reactive": "^0.9.0"
"socket.io-client": "^4.4.1"

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
dafflcommented, Jul 4, 2022

@RobMaple Yep, that was totally it. I am seeing the same error now. It appears that a Socket.io socket still isn’t Node Event Emitter compatible and does not have the addListener method. The following fixes it:

    const socket = io('http://localhost:3030');
    socket.addListener = socket.addEventListener;
    const client = feathers()
      .configure(socketioClient(socket))
      .configure(rx({ idField: 'id' }));

This should probably just be aliased in the client so that the service is fully event emitter compatible.

0reactions
claustrescommented, Jul 7, 2022

You are right, I did not have a look to these tests. So I started https://github.com/feathersjs-ecosystem/feathers-reactive/pull/192 and the behavior seems to me a little strange but maybe my tests are not right.

It seems that the reactive listener is correctly called when the client initiates the service operations itself but not when they are initiated server-side. It seems to be almost the case when initiated by another client except the created event that is missed in the test. Any insight is welcome @daffl.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot call method 'addEventListener' of null - Stack Overflow
Your code is in the <head> => runs before the elements are rendered, so document.getElementById('compute'); returns null, as MDN promise.
Read more >
Lost reference to this in LWC with addEventListener
It's an anti-pattern because bind() returns a new function and thus the component can't call removeEventListener() with the same function ...
Read more >
Create an HTTPS listener for your Application Load Balancer
The load balancer uses a server certificate to terminate the front-end connection and then decrypt requests from clients before sending them to the...
Read more >
Troubleshooting AlwaysOn availability group listener creation ...
When you create a listener in SQL Server, Windows cluster creates a client access point resource. If SQL Server cannot create a listener,...
Read more >
Place Autocomplete | Maps JavaScript API - Google Developers
You can use the returned place ID with calls to the Places, Geocoding, Directions or Distance Matrix services. Note: The name property will...
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