-
-
Notifications
You must be signed in to change notification settings - Fork 496
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
Running Migrations with es modules #2631
Comments
I believe you can't use folder based discovery if you want native ESM. In other words, you can't use env vars for the CLI as that implies folder based discovery - you will need a CLI config file where you use
right, i remember now, we compile the code to CJS, so effectively we still have require calls there even tho not in the TS source code edit: obviously the validation itself is correct, you are trying to run the CLI without configuring where it should look for entities also note that |
Will try it out. Thanks. I think i'll just give up on this es-modules thing ( and just downgrade some of the projects that have moved to esm ) since that is the sole reason i am even trying this out.
Yeah that's that. I remeber reading about something that you added via |
That has a different purpose, to allow using named imports. To support dynamic imports we will need to wait for TS 4.6+ most probably, as they removed the Maybe I could had this as part of some postprocessing - after edit: maybe the eval trick would be actually worth it, we could move it to a helper in utils class, will give that a try as I would very much like to support ESM as much as possible in v5 |
How would that work tho ? using a normal Edit: never mind, i realized it has nothing to do with that. Thanks for talking the time to look into this. |
We would have dynamic imports in the compiled ORM code, so folder based discovery would work out of box probably. So you could have just the |
Just tried and it works fine for the compiled files, in CJS projects in behaves a bit weirdly but that would be workaroundable. But looks like it breaks with ts-node so it breaks tests that uses folder based discovery. I can offer doing this conditionally, based on an env var, e.g. But there is another gotcha, which is running migrations. They also work with file system, and use In general seems like the ecosystem is not ready yet, too many obstacles for no actual benefit (apart from being stuck on some older versions of things that moved forward of course, which sucks). |
By setting `MIKRO_ORM_DYNAMIC_IMPORTS` we now get a dynamic import even tho we still compile to CommonJS. This enabled support for folder based discovery when using ES modules. Related: #2631
yeah, maybe typescript 4.6 will have what we need. Anyways thanks for looking into this. Maybe If you want feel free to close this and open/reopen if ever needed. |
actually umzug does support this, although a bit more verbose than just swapping require/import |
Looking good!
I guess we also need to introduce |
that's great ! |
hey Martin, i've pushed to the same repo 1st problem, if you have any kind of relation when running migrations it won't work if the extension is not specified (ex: 2nd problem, migrations are always created in the dist( with ts extension ) folder and not in src, maybe i missed something from the commit. if you have the time, any type of help is much appreciated. EDIT: tbh 1st problem is really not a problem since we can always just add the |
Well, we can emit the migrations to "correct place" based on the |
I did built the code and the tried to run migrations.
that's ideal yes, but i am using |
My point is, that if you set up the CLI to run in JS context, you will need to manually compile things first. The CLI can't do this dynamically, you need to provide the configuration so it knows what it should do. To run CLI in ts-node context, you would have to adjust your package.json to enable this behaviour (that's the Note that I am able to get around that by using this:
So again, I can offer the fix of where TS migration gets generated, with that you can generate TS, compile to JS and use the CLI to run the JS migrations. Will ship that in a minute.
Btw there is also no point of handling the ALS context explicitly, as ALS is used by default in v5. |
This works really good, thanks ! |
Hey Martin,
After some debugging it seems it fails here
And the error most likely comes from This esm modules.. 😵💫 I would assume it needs to be somehow relative when using windows and es modules since absolute paths are not supported on windows. issue |
Describe the bug
There is no way of running migration using the CLI with es modules.
Stack trace
To Reproduce
Steps to reproduce the behavior:
Expected behavior
I would like to be able to run
migration-create --initial
.Versions
The text was updated successfully, but these errors were encountered: