yeswecode
yeswecode

Reputation: 303

Uncaught TypeError: Object #<Object> has no method 'publish'

I've got console error:

Uncaught TypeError: Object #<Object> has no method 'publish'

There is a line in my server/server.js (console says that the error is here)

Meteor.publish("votes");

p.s. In model.js there is this line:

Votes = new Meteor.Collection("votes");

and in client/client.js there is

Meteor.subscribe("votes");

(it does not swear on the client part)

Thanks:)

Upvotes: 2

Views: 1330

Answers (3)

yeswecode
yeswecode

Reputation: 303

The fix is - "meteor update" :)

Upvotes: 1

Stuart Updegrave
Stuart Updegrave

Reputation: 688

It's been a while since this was asked, but since I just ran across and figured out the same problem ...

I suspect you have your Meteor.publish("votes"); call in a file that's shared between client and server, meaning it executes in both contexts.

The client representation of the Meteor class doesn't support publish, only the server.

If you move this call into a server-only file (such as in <project_name>/server) or inside a server execution context like below, the error should go away.

if (Meteor.isServer) {
    Meteor.publish("votes", {
        return Votes.find(); // or whatever you like
    });
}

Upvotes: 1

emgee
emgee

Reputation: 1234

Your publish function should contain an actual function of what to publish.

From the docs:

To publish records to clients, call Meteor.publish on the server with two parameters: the name of the record set, and a publish function that Meteor will call each time a client subscribes to the name.

So the function should look like:

Meteor.publish("votes", function () {
  return Votes.find();
});

That may or may not be the problem you're running into here, but is the first problem I see.

Upvotes: 0

Related Questions