balmasi / migrate-mongoose

A node based migration framework for mongoose supporting ES6 migrations
MIT License
262 stars 83 forks source link

Unexpected Identifier - Cannot find whats wrong #46

Open adnanchang opened 5 years ago

adnanchang commented 5 years ago

Hi,

So I setup everything, including a migrate.json file and created the migration using:

migrate create dark-theme-apply
/* eslint-disable no-param-reassign */
import Setting from '../src/server/models/Setting';

/**
 * Make any changes you need to make to the database here
 */
async function up() {
  // Write migration here
  await new Promise((resolve, reject) => {
    try {
      const settingsToChange = Setting.find({ darkTheme: { $exists: false } });

      settingsToChange.forEach((setting) => {
        setting.darkTheme = false;
        setting.save();
      });

      resolve();
    } catch (err) {
      reject(err);
    }
  });
}

/**
 * Make any changes that UNDO the up function side effects here (if possible)
 */
async function down() {
  // Write migration here
}

export default { up, down };

On running the following command

migrate up dark-theme-apply

I get the following error:

(node:10208) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.

Synchronizing database with file system migrations...
Unexpected identifier

EDIT: Apparently, the error goes away when I dont use import but then when I use require it still doesnt work

vslepkan commented 4 years ago

I have the same problem. Any updates?

JSandmark commented 4 years ago

Hi! It sounds like you normally use Babel or something to build your js. The file you used to import, but now require in your migration file, could you please verify that that file does not contain imports / export default directly or indirectly in nested requires?

vslepkan commented 4 years ago

Hi, But it contains ES6 modules like in examples from the readme.