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

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

문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top