Error with publish/subscribe

tasks.js

import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
 
export const Tasks = new Mongo.Collection('tasks');

if(Meteor.isServer) {
    Meteor.publish('tasks', function tasksPublication() {
        return Tasks.find();
    });
}

TasksList.jsx

import Tasks from '../../api/tasks.js';
import { createContainer } from 'meteor/react-meteor-data';
...
TasksList.propTypes = {
    tasks: PropTypes.array.isRequired,
}
...
export default createContainer(() => {
    Meteor.subscribe('tasks');
    return {
        tasks: Tasks.find({}, {sort: {createdAt: -1}}).fetch(),
    };
}, TasksList);

Server: main.js

import '../imports/api/tasks';

I get this error:

Uncaught TypeError: Tasks.find is not a function

at this line

tasks: Tasks.find({}, {sort: {createdAt: -1}}).fetch(),

Please help me!

1 Like

I solved it:
I made a mistake, it should be

import {Tasks} from '../../api/tasks.js';