Skip to content

Commit

Permalink
refactor(resolve): remove tryEsmOnly flag (#18394)
Browse files Browse the repository at this point in the history
  • Loading branch information
sapphi-red authored Oct 18, 2024
1 parent 159b4f4 commit 7cebe38
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
20 changes: 1 addition & 19 deletions packages/vite/src/node/plugins/resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
Expand Down
1 change: 0 additions & 1 deletion packages/vite/src/node/ssr/fetchModule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ export async function fetchModule(
isProduction,
root,
packageCache: environment.config.packageCache,
tryEsmOnly: true,
webCompatible: environment.config.webCompatible,
},
undefined,
Expand Down

0 comments on commit 7cebe38

Please sign in to comment.