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

fix(cli): use module: 'nodenext' when registering ts-node #5514

Merged
merged 1 commit into from
May 31, 2024

Conversation

vinialbano
Copy link
Contributor

Update configuration to allow mikro-orm-esm to work with newer versions of tsconfig.

#5427

Copy link

codecov bot commented Apr 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.74%. Comparing base (a6defc1) to head (3a19e93).
Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff            @@
##           master    #5514    +/-   ##
========================================
  Coverage   99.74%   99.74%            
========================================
  Files         260      260            
  Lines       17937    17937            
  Branches     3803     4355   +552     
========================================
  Hits        17892    17892            
  Misses         45       45            

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@B4nan
Copy link
Member

B4nan commented Apr 29, 2024

are you sure this doesn't break CJS projects? i think we could maybe remove the overrides completely, as this should be now all taken from the project's tsconfig. maybe we could keep the old behavior when there is no tsconfig found.

@B4nan
Copy link
Member

B4nan commented May 31, 2024

Ok, now I am finally able to reproduce this. You confused me with the mikro-orm-esm, to me that works just fine with ESM projects (as the https://github.com/mikro-orm/guide). I had to use mikro-orm command instead and remove type: 'module' from the package.json file to see that error.

@B4nan B4nan changed the title Update ConfigurationLoader to use 'nodenext' when registering ts-node fix(cli): use module: 'nodenext' when registering ts-node May 31, 2024
@B4nan B4nan merged commit 8695524 into mikro-orm:master May 31, 2024
11 checks passed
@vinialbano
Copy link
Contributor Author

Awesome! Thanks so much, @B4nan. That will help a lot in a project that I'm working on. We were manually fixing in node_modules so far haha

@Far4way
Copy link

Far4way commented Jun 4, 2024

This change breaks CLI when using mikro-orm as part of a project that still uses "moduleResolution": "node".

Shouldn't a breaking change be part of a major update ?

@B4nan
Copy link
Member

B4nan commented Jun 4, 2024

It works fine on my end, can you provide a complete repro? I wouldn't do it if I would consider it breaking, I am sure we can make this work conditionally if needed.

Btw one way around this is having a separate tsconfig.orm.json for the CLI, where you override the moduleResolution to nodenext. You would point to it in the package.json ORM options and the CLI will prefer that.

@Far4way
Copy link

Far4way commented Jun 4, 2024

I can't provide a link to the repo where I have the issue, but I tried the following steps (10min to complete a reproduction) and had the same issue :

  1. Create a monorepo with nx
  2. setup an angular app
  3. setup a nestjs app
  4. install mikro/orm
  5. 'try' to use cli

I did end up finding a solution where I indeed modified the main tsconfig and overwrote the main file in my nestjs and angular apps.

But again, this change is breaking, and I shouldn't have to modify config files because I updated to the last minor of mikro-orm.

I don't think that I'm familiar enough to help you make this whole thing conditional, but that sure would be great!

@B4nan
Copy link
Member

B4nan commented Jun 4, 2024

I can't provide a link to the repo where I have the issue

I don't want your repository, I don't care about your app, I want a minimal example that shows the problem.

Create a monorepo with nx

I never used nx and I am not interested in learning it now.

But again, this change is breaking, and I shouldn't have to modify config files because I updated to the last minor of mikro-orm.

Without a repro this is just a claim, it works just fine on my end 🤷

So again, please provide a reproduction if you think it's breaking, then we can do something about it.

@Far4way
Copy link

Far4way commented Jun 4, 2024

Here is a fork of the nestjs-example-app (quickest way to reproduce the problem) : nestjs-example-app_6.2.9.

The only change made to the forked repo is adding "moduleResolution": "node" to compilerOptions in the tsconfig.json.

In 6.2.8, using mikro-orm debug we get the following output :

$ npx mikro-orm debug
Current MikroORM CLI configuration
 - dependencies:
   - mikro-orm 6.2.8
   - node 20.11.0
   - knex not-found
   - mysql2 not-found
   - typescript not-found
 - package.json found
 - ts-node enabled
 - searched config paths:
   - /nestjs-example-app_6.2.9/src/mikro-orm.config.ts (found)
   - /nestjs-example-app_6.2.9/dist/mikro-orm.config.js (not found)
   - /nestjs-example-app_6.2.9/mikro-orm.config.ts (not found)
   - /nestjs-example-app_6.2.9/src/mikro-orm.config.js (not found)
   - /nestjs-example-app_6.2.9/mikro-orm.config.js (not found)
 - configuration found
 - database connection failed (connect ECONNREFUSED 127.0.0.1:3307)
 - will use `entities` array (contains 5 references and 0 paths)

In 6.2.9 :

$ npx mikro-orm debug
Current MikroORM CLI configuration
 - dependencies:
   - mikro-orm 6.2.9
   - node 20.11.0
   - typescript not-found
 - package.json found
 - ts-node enabled
 - searched config paths:
   - /nestjs-example-app_6.2.9/src/mikro-orm.config.ts (found)
   - /nestjs-example-app_6.2.9/dist/mikro-orm.config.js (not found)
   - /nestjs-example-app_6.2.9/mikro-orm.config.ts (not found)
   - /nestjs-example-app_6.2.9/src/mikro-orm.config.js (not found)
   - /nestjs-example-app_6.2.9/mikro-orm.config.js (not found)
- configuration not found ( Unable to compile TypeScript:
error TS5109: Option 'moduleResolution' must be set to 'NodeNext' (or left unspecified) when option 'module' is set to 'NodeNext'.
)

Hoping this much is good enough !

B4nan added a commit that referenced this pull request Jun 4, 2024
@B4nan
Copy link
Member

B4nan commented Jun 4, 2024

This should help d5d7f38

I really don't understand what happened, it was working just fine and now I can reproduce in the same repo where it worked before.

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.

None yet

3 participants