fix(core): detect ts-node
when using esm loader
#5332
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The problem
When using mikroorm in typescript ESM project and using cli,
.ts
config andentitiesTs
are not taken into account. This is because ts-node is not detected for node > 16.20 when usingts-node/esm
loader as node option https://github.com/TypeStrong/ts-node?tab=readme-ov-file#node-flags-and-other-tools (directly or usingmikro-orm-esm
binary).If we have the orm script in
package.json
and definedconfigPaths
:And run
npm run orm-esm-binary debug
ornpm run orm-node-loader debug
in development, you will see the messageFor node 16 this works as ts-node is detected because it will install internal ts-node symbol in process.
Description of the solution
Adding the check for
ts-node/esm
inprocess.execArgv
(args passed to nodejs runtime: https://nodejs.org/api/process.html#processexecargv) in this case--loader
option is passed as nodejs option, will correctly detect ts-node and ts config is used when using cli.Alternative solutions