Skip to content

Commit

Permalink
fix: tolerate undefined parent in hookNodeResolve callback (#5664)
Browse files Browse the repository at this point in the history
  • Loading branch information
aleclarson authored Nov 12, 2021
1 parent 68e8e35 commit d788682
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/vite/src/node/ssr/ssrModuleLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,15 @@ async function nodeImport(

// When an ESM module imports an ESM dependency, this hook is *not* used.
const unhookNodeResolve = hookNodeResolve(
(nodeResolve) => (id, parent, isMain, options) =>
id[0] === '.' || isBuiltin(id)
? nodeResolve(id, parent, isMain, options)
: viteResolve(id, parent.id)
(nodeResolve) => (id, parent, isMain, options) => {
if (id[0] === '.' || isBuiltin(id)) {
return nodeResolve(id, parent, isMain, options)
}
if (!parent) {
return id
}
return viteResolve(id, parent.id)
}
)

let url: string
Expand Down

0 comments on commit d788682

Please sign in to comment.