Skip to content

Commit 7cebe38

Browse files
authored
refactor(resolve): remove tryEsmOnly flag (vitejs#18394)
1 parent 159b4f4 commit 7cebe38

File tree

2 files changed

+1
-20
lines changed

2 files changed

+1
-20
lines changed

packages/vite/src/node/plugins/resolve.ts

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { hasESMSyntax } from 'mlly'
77
import type { Plugin } from '../plugin'
88
import {
99
CLIENT_ENTRY,
10-
DEFAULT_EXTENSIONS,
11-
DEFAULT_MAIN_FIELDS,
1210
DEP_VERSION_RE,
1311
ENV_ENTRY,
1412
FS_PREFIX,
@@ -126,7 +124,6 @@ interface ResolvePluginOptions {
126124
// if the specifier requests a non-existent `.js/jsx/mjs/cjs` file,
127125
// should also try import from `.ts/tsx/mts/cts` source file as fallback.
128126
isFromTsImporter?: boolean
129-
tryEsmOnly?: boolean
130127
// True when resolving during the scan phase to discover dependencies
131128
scan?: boolean
132129
// Appends ?__vite_skip_optimization to the resolved id if shouldn't be optimized
@@ -818,22 +815,7 @@ export function tryNodeResolve(
818815
const resolveId = deepMatch ? resolveDeepImport : resolvePackageEntry
819816
const unresolvedId = deepMatch ? '.' + id.slice(pkgId.length) : id
820817

821-
let resolved: string | undefined
822-
try {
823-
resolved = resolveId(unresolvedId, pkg, options)
824-
} catch (err) {
825-
if (!options.tryEsmOnly) {
826-
throw err
827-
}
828-
}
829-
if (!resolved && options.tryEsmOnly) {
830-
resolved = resolveId(unresolvedId, pkg, {
831-
...options,
832-
isRequire: false,
833-
mainFields: DEFAULT_MAIN_FIELDS,
834-
extensions: DEFAULT_EXTENSIONS,
835-
})
836-
}
818+
let resolved = resolveId(unresolvedId, pkg, options)
837819
if (!resolved) {
838820
return
839821
}

packages/vite/src/node/ssr/fetchModule.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ export async function fetchModule(
6565
isProduction,
6666
root,
6767
packageCache: environment.config.packageCache,
68-
tryEsmOnly: true,
6968
webCompatible: environment.config.webCompatible,
7069
},
7170
undefined,

0 commit comments

Comments
 (0)