fix(config): treat all files as ESM on deno #18081
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.
Description
The CJS detection logic that checks whether the CJS entry of vite itself is used is based around
package.json
detection. With Deno this assumption is not true anymore as most Deno projects don't have apackage.json
file. Instead they either have adeno.json
or adeno.jsonc
file. Projects in Deno are always in ESM too.When using vite in Deno you'd always see this warning unless you added a
package.json
withtype: module
:Ultimately, this is caused by the check here
vite/packages/vite/src/node/utils.ts
Line 430 in 35cf59c
Which infers that the current project is in CJS. This PR addresses that by making vite aware of Deno projects. When running inside Deno, we'll not just check for
package.json
, but alsodeno.json
anddeno.jsonc
too.I'm not too familiar with the testing setup here in vite and would need some pointers for adding a test. Where do these go here?
Fixes denoland/deno#25574