-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
feat: added support for ESM config files #982
Conversation
Hi, thanks for the PR. You can update the docs by making a PR for this file in the main sequelize repo; https://github.com/sequelize/sequelize/blob/main/docs/manual/other-topics/migrations.md Can you show how it fails on Node <12.20? We will be dropping support for Node 10 soonish, so I'm wondering if we should put this on hold until then or that we can merge this with the next release. |
If you use Node version earlier than 12.20, you'll get the following error But if I run the other tests they pass In essence For users still using Node 10 sequelize cli will work exactly the same way, since all the other tests pass, with the exception of the ESM tests, which won't work in Node 10 anyway. |
I'll create a PR for the docs and mention this PR, do you want me to add code to skip these tests in case the runtime is Node 10? |
You read my mind, I was about to ask that. Would be great if you could do that and then I'll assign a maintainer to look at this PR |
2eda7de
to
9514c19
Compare
@WikiRik I didn't know where to put I've also opened sequelize/sequelize#13669 for the doc changes. |
I think we can get to this from Wednesday on :) we'll discuss which node versions to support on Tuesday |
ping & thanks |
The current solution is going to swallow errors if the file is esm but throws an error. Instead of a fallback to require, I'd opt for feature-detecting |
We can try to detect specific ESM errors and re-throw if the module itself errors. |
We can detect whether If the require fails, or the exported promise rejected, |
This wasn't merged, right? On a new project using
|
It was (through #987) but it only impacts being able to load esm config files, generation of files hasn't been updated yet |
Ah, thanks for clarification |
Pull Request check-list
Please make sure to review and check all of these items:
npm run test
pass with this change (including linting)?Description of change
Added support for config files that are ESM, usually the migrations themselves are generated so they are commonjs.
But on the other hand the config could be in ESM in case the backend uses ESM.
This PR fixes that by trying to import the config file as an ECMAScript module first, and if it fails it fallbacks to CommonJS.
I've also had to change the babel config, so that it won't transpile the dynamic import to CommonJS as well.
Let me know if a change to the docs is necessary, and if so where to put it.
This PR also means that the new tests will fail on Node versions older than 12.20, but the failure will be graceful and CommonJS will work instead, since ESM doesn't work in Node versions earlier than that.