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: use .mjs extension for cached optimized deps #4064

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions packages/vite/src/node/optimizer/index.ts
Expand Up @@ -270,6 +270,9 @@ export async function optimizeDeps(
splitting: true,
sourcemap: true,
outdir: cacheDir,
outExtension: {
'.js': '.mjs'
},
treeShaking: 'ignore-annotations',
metafile: true,
define,
Expand All @@ -288,7 +291,7 @@ export async function optimizeDeps(
for (const id in deps) {
const entry = deps[id]
data.optimized[id] = {
file: normalizePath(path.resolve(cacheDir, flattenId(id) + '.js')),
file: normalizePath(path.resolve(cacheDir, flattenId(id) + '.mjs')),
src: entry,
needsInterop: needsInterop(
id,
Expand Down Expand Up @@ -328,7 +331,7 @@ function needsInterop(
// if a peer dependency used require() on a ESM dependency, esbuild turns the
// ESM dependency's entry chunk into a single default export... detect
// such cases by checking exports mismatch, and force interop.
const flatId = flattenId(id) + '.js'
const flatId = flattenId(id) + '.mjs'
let generatedExports: string[] | undefined
for (const output in outputs) {
if (
Expand Down