Open joezappie opened 2 years ago
I'm having the same issue
I'm experiencing similar issue.
I'm having the same issue as well.
I had the same issue when running from a quick and dirty docker image based on node-20, with migrate-mongo installed globally running the raw scripts, rather than from within a package. I worked around it by changing the migrate-mongo-config.js and migrations/* scripts to be non-esm.
In migrate-mongo-config.js:
module.exports = { ... }
instead of const config = { ... }; export default config;
In scripts:
module.exports.up = async...
instead of export const up = async...
, similarly for downconst { ObjectId } = require('../path/to/mongodb/lib/index.js')
instead of import { ObjectId } from 'mongodb'
new ObjectId()
instead of just ObjectId()
Hope that helps someone looking for a quick fix.
Describe the bug I am getting an error about using import in a project that uses ESM.
I see line 101 in migrationsDir is doing a require thats surrounded by a try catch. Doesn't seem like e.code === ERR_REQUIRE_ESM as its not running that and rethrowing the error.
Since it seems like the moduleSystem config variable was recently added, how about using that instead of a try catch to run the appropriate loader?
To Reproduce I am using this via the programmable API.
Expected behavior Should properly import when in esm environment.
Additional context I am running this as a bin script. Package.json is set to type module and my config file for migrate-mongo has moduleSystem: 'esm'.