Fix ESM module resolution in Vitest due to package.json
format
#420
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.
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 theexports.*.default
key. However, when running inside of Vitest, it uses theexports.*.node
resolution because Vitest is targetting the node environment. By simply adding aimport
key to the builtpackage.json
file this fixes the issues within Vitest. Also worth noting, if theimport
key is below thenode
key, Vitest still uses thenode
key resolution instead.