Skip to content
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: Object #<Object> has no method 'on' #15

Closed
lc3t35 opened this issue Mar 18, 2014 · 11 comments
Closed

TypeError: Object #<Object> has no method 'on' #15

lc3t35 opened this issue Mar 18, 2014 · 11 comments

Comments

@lc3t35
Copy link

lc3t35 commented Mar 18, 2014

When i launch mrt, i have the following error :

W20140318-16:09:09.937(0)? (STDERR) /root/.meteor/tools/f3947a4651/lib/node_modules/fibers/future.js:173
W20140318-16:09:09.939(0)? (STDERR)                         throw(ex);
W20140318-16:09:09.944(0)? (STDERR)                               ^
W20140318-16:09:09.947(0)? (STDERR) TypeError: Object #<Object> has no method 'on'
W20140318-16:09:09.948(0)? (STDERR)     at app/server/Accounts.js:25:12
W20140318-16:09:09.950(0)? (STDERR)     at app/server/Accounts.js:35:3
W20140318-16:09:09.951(0)? (STDERR)     at /D/poc-users/.meteor/local/build/programs/server/boot.js:155:10
W20140318-16:09:09.952(0)? (STDERR)     at Array.forEach (native)
W20140318-16:09:09.953(0)? (STDERR)     at Function._.each._.forEach (/root/.meteor/tools/f3947a4651/lib/node_modules/underscore/underscore.js:79:11)
W20140318-16:09:09.954(0)? (STDERR)     at /D/poc-users/.meteor/local/build/programs/server/boot.js:82:5
=> Exited with code: 8

Here is the code snippet in Accounts.js

Meteor.publish("userStatus", function() {
  return Meteor.users.find({
    "status.online": true
  });
});
....
UserStatus.on("sessionLogin", function(advice) {
  winston.log('info', 'User login', { metadata : JSON.stringify(advice)});
  return ;
});

mrt --version
Meteorite version 0.7.2
Release 0.7.1.2
smart.json

{
  "packages": {
    "collectionFS": {},
    "bootstrap-3": {},
    "winston": {},
    "winston-mongodb": {
      "path": "./packages/meteor-winston-mongodb"
    },
    "ogno-admin": {},
    "iron-router": {},
    "collection2": {},
    "datatables": {},
    "winston-client": {},
    "user-status": {},
    "roles": {}
  }
}

.meteor/packages

standard-app-packages
preserve-inputs
accounts-base
accounts-ui
accounts-password
roles
user-status
iron-router
collectionFS
cfsfilehandlerserver
cfs-public-folder
winston
winston-mongodb
winston-client
collection2
ogno-admin
datatables
bootstrap-3

Was working fine until i add the roles package ...
mrt test-packages user-status works fine - all green.

@mizzao
Copy link
Collaborator

mizzao commented Mar 18, 2014

Check history: UserStatus is now UserStatus.events, and sessionLogin is now connectionLogin. Sorry for the hassle.

I would also recommend just putting advice directly in metadata rather than stringifying it. Why not just leave it as nested JSON?

@mizzao mizzao closed this as completed Mar 18, 2014
@lc3t35
Copy link
Author

lc3t35 commented Mar 18, 2014

i can see that the package i have is 0.2.0 when i run mrt :

user-status
    tag: https://github.com/mizzao/meteor-user-status.git#v0.2.0

this is confirmed by packages/user-status/smart.json

{
  "name": "user-status",
  "description": "User connection and status tracking for meteor",
  "homepage": "https://github.com/mizzao/meteor-user-status",
  "author": "Andrew Mao  (http://www.andrewmao.net)",
  "version": "0.2.0",
  "git": "https://github.com/mizzao/meteor-user-status.git",
  "packages": {}
}

i did mrt remove user-status then
mrt add user-status
Now everything is OK back to 0.3.4 ;)

maybe atmosphere was out of sync when i did mrt add ?

@lc3t35
Copy link
Author

lc3t35 commented Mar 18, 2014

Copy/paste from console.log for JSON.stringify(advice) -> thanks for the review !

@mizzao
Copy link
Collaborator

mizzao commented Mar 18, 2014

I don't understand your last comment - do you still have a problem or is it fixed?

I suggest you update to newer versions if possible; we are taking advantage of improved connection handling in newer versions of Meteor. See meteor/meteor#1769.

@lc3t35
Copy link
Author

lc3t35 commented Mar 18, 2014

it's fixed but i don't know why i was in 0.2.0 !

@lc3t35
Copy link
Author

lc3t35 commented Mar 20, 2014

user-status
tag: https://github.com/mizzao/meteor-user-status.git#v0.3.4

Looking for an example in the tests, i've tryed this

UserStatus.events.on("connectionLogin", function(advice) {
  console.log(">>> user login");
});

But there is still TypeError: Cannot call method 'on' of undefined ???

if i look in the console, UserStatus has only the server side functions (defined in monitor.coffee) not the one of status.coffee : events and connections.

@mizzao
Copy link
Collaborator

mizzao commented Mar 20, 2014

You can't use UserStatus.events in the client. That is a server side event emitter. monitor.coffee is client code.

@lc3t35
Copy link
Author

lc3t35 commented Mar 20, 2014

Ok moved to server side , works fine -> Why in package.js : api.export('UserStatus'); // on both then ?

@mizzao
Copy link
Collaborator

mizzao commented Mar 20, 2014

UserStatus has different exports on the server and client, but the object is available on both.

@lc3t35
Copy link
Author

lc3t35 commented Mar 20, 2014

Thank you, perhaps clarify the documentation on what is available on client and server side for the same UserStatus.

@mizzao
Copy link
Collaborator

mizzao commented Mar 20, 2014

Yes, good idea. I will certainly do that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants