Meteor.publish is not a function
Asked Answered
S

2

7

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.

Superorder answered 9/7, 2015 at 19:2 Comment(0)
S
16

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.

Svensen answered 9/7, 2015 at 19:6 Comment(4)
That does fix the issue... although I don't understand why my structure doesn't solve the problem as my understanding was anything in the server folder would only execute on the server.Superorder
server needs to be lower cased. Server will share to both the client and the server.Svensen
Ha, you're kidding me. Ah man... So when I change my app structure to be the proper case... it breaks. Why would that be?Superorder
My router routes were in the server folder. Sheesh. I'm good now. Thanks for the tips.Superorder
S
1

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.

Stoneman answered 9/7, 2015 at 19:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.