Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESM Support #351

Merged
merged 6 commits into from Mar 31, 2022
Merged

ESM Support #351

merged 6 commits into from Mar 31, 2022

Conversation

nathan-knight
Copy link
Contributor

@nathan-knight nathan-knight commented May 5, 2021

This resolves #248

Checklist
  • npm test passes and has 100% coverage
  • README.md is updated

These changes allow migrate-mongo to work in projects with "type": "module" set in their package.json file without disrupting other configurations or requiring additional configuration.

Config files should use export default { instead of module.exports = {
Migrations should look like:

export const up = async (db, client)  => { ... }
export const down = async (db, client)  => { ... }

@coveralls
Copy link

coveralls commented May 5, 2021

Coverage Status

Coverage remained the same at 100.0% when pulling 216d086 on nathan-knight:esm-support into 4906ff2 on seppevs:master.

@ghost
Copy link

ghost commented May 6, 2021

This feature looks interesting. Could you add tests please :) ?

@nathan-knight
Copy link
Contributor Author

This feature looks interesting. Could you please add tests please :) ?

I added some tests and fixed some existing tests that did not work on Windows.

@ghost
Copy link

ghost commented May 7, 2021

This feature looks interesting. Could you please add tests please :) ?

I added some tests and fixed some existing tests that did not work on Windows.

Nice !

@lattam
Copy link

lattam commented May 20, 2021

Great work! When do think this could be merged and released?
Thank you

lib/env/config.js Outdated Show resolved Hide resolved
try {
return Promise.resolve(moduleLoader.require(configPath));
} catch (e) {
if (e.code === 'ERR_REQUIRE_ESM') {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nathan-knight
I observe instability here (potentially depending on the Node version used ???)
This code used to work for me, I used it some weeks ago but now for the same usage I no longer have this error code thrown by the Node's require so it seems unstable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This error only occurs on newer versions of Node that are configured to use ES modules

lib/env/config.js Outdated Show resolved Hide resolved
lib/env/config.js Outdated Show resolved Hide resolved
nathan-knight and others added 2 commits June 16, 2021 12:39
Co-authored-by: Antoine <73850194+Antoineeeee-tech@users.noreply.github.com>
Co-authored-by: Antoine <73850194+Antoineeeee-tech@users.noreply.github.com>
@boycce
Copy link

boycce commented Sep 16, 2021

Nice, when will this be released?

@nathan-knight
Copy link
Contributor Author

Nice, when will this be released?

I'm available to make any remaining changes that are required. It just needs someone with write access to merge the PR if it is good to go.

@nuno-ferrao
Copy link

Any idea when this update will be released? Would be very useful to me :)

@joezappie
Copy link

I too am looking to use this but have type: "module" so I can use import in my project. This is breaking this tool as node complains:

RROR: Must use import to load ES Module: C:...\migrate-mongo-config.js
require() of ES modules is not supported.

@nathan-knight
Copy link
Contributor Author

@seppevs Are there any other changes that are needed for this to be merged?

@joshhansen
Copy link

Just ran into this issue... looks like a ready-made solution...? This would let me adopt migrate-mongo, which I'd love to be able to do!

@ksmithut
Copy link

As a workaround, I was able to get it to work by having my migration files still be in common js with the .cjs extensions, then set the migrationFileExtension option in my config file to '.cjs'. Not a great solution since it seems like it's so close to getting merged in, but my migration files aren't terrible big, and wouldn't be a bit deal to migrate the files once this gets fixed.

@MattG561
Copy link

Any update on the release date for this? This PR has been open since May...

@seppevs seppevs merged commit 4b9a955 into seppevs:master Mar 31, 2022
@seppevs
Copy link
Owner

seppevs commented Mar 31, 2022

Thank you for your contribution, and sorry it took so long. I have merged your PR to the master branch, and improved the ESM support a bit further. This feature has finally landed in migrate-mongo 9.0.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for ES6 imports
10 participants