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 ESM module resolution in Vitest due to package.json format #420

Merged
merged 1 commit into from
Feb 23, 2024

Conversation

K3TH3R
Copy link
Contributor

@K3TH3R K3TH3R commented Feb 21, 2024

This originally started as an investigation into an issue in RxDB which uses mingo as a dependency. My problem was essentially similar to pubkey/rxdb#5452.

After some initial digging and futzing around, I discovered that this was due to how Vitest's module resolution works: vitest-dev/vitest#4233

Essentially, when building for the web, Vite will properly resolve the ESM import on the exports.*.default key. However, when running inside of Vitest, it uses the exports.*.node resolution because Vitest is targetting the node environment. By simply adding a import key to the built package.json file this fixes the issues within Vitest. Also worth noting, if the import key is below the node key, Vitest still uses the node key resolution instead.

Copy link

codecov bot commented Feb 23, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.81%. Comparing base (befab12) to head (8c99a08).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #420   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files         294      294           
  Lines        4227     4227           
  Branches      992      992           
=======================================
  Hits         4177     4177           
  Misses         44       44           
  Partials        6        6           
Flag Coverage Δ
unittests 98.81% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@kofrasa kofrasa merged commit 6e3d71c into kofrasa:main Feb 23, 2024
8 checks passed
@kofrasa
Copy link
Owner

kofrasa commented Feb 23, 2024

Thanks for the contribution.

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.

2 participants