diff --git a/packages/vite/src/node/plugins/resolve.ts b/packages/vite/src/node/plugins/resolve.ts index b930324db960fe..a51b7c20a0c047 100644 --- a/packages/vite/src/node/plugins/resolve.ts +++ b/packages/vite/src/node/plugins/resolve.ts @@ -7,8 +7,6 @@ import { hasESMSyntax } from 'mlly' import type { Plugin } from '../plugin' import { CLIENT_ENTRY, - DEFAULT_EXTENSIONS, - DEFAULT_MAIN_FIELDS, DEP_VERSION_RE, ENV_ENTRY, FS_PREFIX, @@ -126,7 +124,6 @@ interface ResolvePluginOptions { // if the specifier requests a non-existent `.js/jsx/mjs/cjs` file, // should also try import from `.ts/tsx/mts/cts` source file as fallback. isFromTsImporter?: boolean - tryEsmOnly?: boolean // True when resolving during the scan phase to discover dependencies scan?: boolean // Appends ?__vite_skip_optimization to the resolved id if shouldn't be optimized @@ -818,22 +815,7 @@ export function tryNodeResolve( const resolveId = deepMatch ? resolveDeepImport : resolvePackageEntry const unresolvedId = deepMatch ? '.' + id.slice(pkgId.length) : id - let resolved: string | undefined - try { - resolved = resolveId(unresolvedId, pkg, options) - } catch (err) { - if (!options.tryEsmOnly) { - throw err - } - } - if (!resolved && options.tryEsmOnly) { - resolved = resolveId(unresolvedId, pkg, { - ...options, - isRequire: false, - mainFields: DEFAULT_MAIN_FIELDS, - extensions: DEFAULT_EXTENSIONS, - }) - } + let resolved = resolveId(unresolvedId, pkg, options) if (!resolved) { return } diff --git a/packages/vite/src/node/ssr/fetchModule.ts b/packages/vite/src/node/ssr/fetchModule.ts index 4e04718ecbe903..70b866ed1834a4 100644 --- a/packages/vite/src/node/ssr/fetchModule.ts +++ b/packages/vite/src/node/ssr/fetchModule.ts @@ -65,7 +65,6 @@ export async function fetchModule( isProduction, root, packageCache: environment.config.packageCache, - tryEsmOnly: true, webCompatible: environment.config.webCompatible, }, undefined,