SirBT
SirBT

Reputation: 1698

How do I correctly import my collection definition?

How do I correctly import my collection definition? I get this error message when as a result of trying to import

The displayed error message

I externalized my collection definition FROM the main myMeteorApp.js file: (My directory structure looked like this:)

/myMeteorApp
/myMeteorApp.js 

...TO the tasks.js file: (My directory structure currently looks like this:)

/myMeteorApp
--/imports/api/tasks.js 

The contents of tasks.js look like this:

import { Mongo } from "meteor/mongo";

const Images = new FS.Collection("images", {
stores: [new FS.Store.FileSystem("images", {path: "~/uploads"})]
});

const buyList = new Mongo.Collection("BuyList");
const WhoAreWe = new Mongo.Collection("whoDb");
const merchantReviews = new Mongo.Collection("MerchantReviews");
const Messages = new Meteor.Collection("messages", {transform:     function (doc) { doc.buyListObj = buyList.find({sessionIDz: {$in: [doc.buyList]}}); return doc; }});

export { Images };
export { buyList };
export { WhoAreWe };
export { merchantReviews };
export { Messages };

I have packages babel-preset-es2015 and ecmascript installed, but these haven't helped.

Looking forward to your help...

Upvotes: 0

Views: 119

Answers (1)

MasterAM
MasterAM

Reputation: 16478

Everything is the chat session we had indicates that your original app used Meteor 1.2, which did not support ES2015 modules. In addition, you did not import them correctly.

Here is a short checklist for import-related issues:

  1. Make sure that your project is actually using Meteor v1.3+ (run meteor --version). Earlier versions did not support the modules feature.
  2. Make sure that you have the ecmascript package installed (run meteor list or cat .meteor/packages | grep ecmascript from your project's root directory. If not, meteor add ecmascript. This is the package used for compiling ES2015.
  3. Make sure that you are using it correctly. There are 2 types of exports:

    • default - import foo from 'imports/bar' goes with export default bar.
    • named - import { foo } from 'imports/bar' goes with export const foo = ..., etc.

Upvotes: 1

Related Questions