Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@vitejs/test-native-compat-mts",
"type": "commonjs",
"private": true
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { defineConfig } from 'vite'

export default defineConfig({})
8 changes: 7 additions & 1 deletion packages/vite/src/node/nativeConfigCompat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,13 @@ export function createNativeConfigCompatPlugin(
return {
name: 'vite:native-config-compat-check',
transform: {
filter: { id: /\.[cm]?[jt]sx?$/ },
filter: {
id: {
include: /\.[cm]?[jt]sx?$/,
// exclude rolldown runtime
exclude: /^\0/,
},
},
async handler(code, id) {
const isESM =
typeof process.versions.deno === 'string' || isFilePathESM(id)
Expand Down
16 changes: 16 additions & 0 deletions packages/vite/src/node/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,13 @@ export function isFilePathESM(
return true
} else if (/\.c[jt]s$/.test(filePath)) {
return false
} else if (filePath.startsWith('\0')) {
// treat virtual modules as ESM
return true
} else if (!path.isAbsolute(filePath)) {
// should not rely on `process.cwd()` as that would depend on
// the environment and make it unreproducible
return false
} else {
// check package.json for type: "module"
try {
Expand All @@ -453,6 +460,15 @@ export function isFilePathFormatExplicit(
if (/\.[mc][jt]s$/.test(filePath)) {
return true
}
if (filePath.startsWith('\0')) {
// treat virtual modules as ESM
return true
}
if (!path.isAbsolute(filePath)) {
// should not rely on `process.cwd()` as that would depend on
// the environment and make it unreproducible
return false
}
try {
const pkg = findNearestPackageData(path.dirname(filePath), packageCache)
return pkg?.data.type === 'module' || pkg?.data.type === 'commonjs'
Expand Down
2 changes: 2 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.