Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor.publish is not a function

I have a publications.js file that ONLY includes

Meteor.publish('org', function(_id){
    return Organizations.findOne(_id);
});

When things render I get this in the console:

Uncaught TypeError: Meteor.publish is not a function

What am I missing here... I'm sure it's painfully obvious.

like image 906
btbJosh Avatar asked Jul 09 '15 19:07

btbJosh


2 Answers

You are probably accidentally running the code on the client. You have two choices:

  1. Place the publish code in a file under the /server directory in your app.
  2. Wrap the above inside of an if (Meteor.isServer) {} block.

(1) Has the advantage of not transmitting the publish code to the client.

Suggested reading: Structuring your application.

like image 50
David Weldon Avatar answered Nov 16 '22 23:11

David Weldon


If the file is at the root, you need to wrap it with:

if ( Meteor.isServer ) { /* ... */ }

The Meteor.publish method only exists on the server.

like image 25
Ivan Avatar answered Nov 17 '22 00:11

Ivan