Meteor ReferenceError when trying to access a collection of from a deployed app using Iron Router

StackOverflow https://stackoverflow.com/questions/21645232

Question

My app is completely functional locally. However, when I deploy it I receive the following error in the javascript console on a page where the collection Posts is supposes to be accessed.

Exception from Deps recompute: ReferenceError: Posts is not defined
at Object.route.data.posts

Here is the router javascript file I'm using which passes on Posts to the template postsLists which won't load when deployed.


Router.configure({
          layoutTemplate: 'layout',
          loadingTemplate: 'loading',
          waitOn: function() { console.log('waiting'); return [Meteor.subscribe('posts'), Meteor.subscribe('files')]; }
        });

        Router.map(function(){
            this.route('postPage', {
                path:'/posts/:_id',
                data: function() {return Posts.findOne(this.params._id); }
            });

            this.route('welcome', {path: '/'});

            this.route('postsList', {path: '/List',
            data: {
                posts: function () {
                return Posts.find({}, {sort: {submitted: -1}});
              }
            }});

            this.route('postSubmit',{
                path:'/submit'
            });
            this.route('yourPosts',{
                path:'/yourposts'
            });
            this.route('officialPosts',{
                path:'/featured'
            });
            this.route('postEdit', {
            path: '/posts/:_id/edit',
            data: function() { return Posts.findOne(this.params._id); }
          });
        });

        var requireLogin = function(){
            if(! Meteor.user()){
                this.render('accessDenied');
                this.stop();
            }
        };

        Router.before(requireLogin, {only: ['postSubmit','postsList','yourPosts','officialPosts','postEdit']});

The site is also accessible at fed.meteor.com.

Thanks in Advance.

Was it helpful?

Solution

You have a javascript error, you can see it in the js console when it says Uncaught TypeError: Object #<Object> has no method 'describe'.

In production mode the file is concatenated so when you have an error like this, the code below it won't execute at all. So this way Posts isn't defined.

You still have the error locally, but the files aren't concatenated so an error in one will not affect the other files and the error wouldn't be that apparent.

You would have to fix your other error for the rest of the code to run.

Nice site btw.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top