New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: Cannot read properties of undefined (reading 'toJSON') #186
Comments
Based on some of the documentation available, it does not require the context to be passed. For example, at https://feathersjs.com/api/events.html, it has an example as show below that doesn't include the context as the third parameter. However, if you follow this example and have feathers-sync enabled, you will get the same error as reported. What would be the best path forward in this case?
|
If I add an empty object such as messages.emit('customEvent', { anything: 'Data can be anything' }, {}) it will avoid the error. However, it seems the fix is to check to see if ctx is undefined. |
I added an additional check that resolves and created a pull request at #187. |
Just an F.Y.I., after further testing, if you try to pass an empty object as a third parameter, although the error goes away, feathers emit will not work and you will not receive events on the client side subscribed to the event. The patch I submitted at #187 solves the issue and makes feathers-sync compatiable with featherjs v5. |
Steps to reproduce
Prior to commit 5106085 I was able to use ctx.service("myservice").emit("created", data) and that would work. However, after the update, it no longer works. The issue is created at service.emit (/usr/app/node_modules/feathers-sync/lib/core.js:55:46) as it does not check to ensure ctx is not undefined.
Is it now a requirement in features to pass the ctx as well when using service.emit? In any case, should there be checking to ensure ctx is not undefined? This seems to be the standard for other code in the same file.
Expected behavior
Event emitted and synced successfully.
Actual behavior
TypeError: Cannot read properties of undefined (reading 'toJSON')
at service.emit (/usr/app/node_modules/feathers-sync/lib/core.js:55:46)
System configuration
Module versions (especially the part that's not working): "3.0.2"
The text was updated successfully, but these errors were encountered: