fix(ssr): viteResolve fallback to absolute id#6126
Conversation
| @@ -216,6 +216,9 @@ async function nodeImport( | |||
| ) => { | |||
| const resolved = tryNodeResolve(id, importer, options, false) | |||
There was a problem hiding this comment.
Note that tryNodeResolve runs first, but won't return a match.
The problematic id is already a fully resolved, absolute path to a file that does exist... maybe this needs to be fixed inside of tryNodeResolve?
There was a problem hiding this comment.
maybe this needs to be fixed inside of
tryNodeResolve?
Vite's internal resolve plugin checks for absolute paths before tryNodeResolve. See here:
vite/packages/vite/src/node/plugins/resolve.ts
Lines 195 to 199 in b45f4ad
| if (!resolved) { | ||
| if (path.isAbsolute(id)) { | ||
| return id | ||
| } |
There was a problem hiding this comment.
Attempt: if tryNodeResolve returns undefined but our id is an absolute path, it might be fully resolved already. Just return it.
There was a problem hiding this comment.
Any reason we shouldn't check for absolute path before the tryNodeResolve call?
|
Does #5495 also fix the issue with absolute paths? |
|
@natemoo-re It looks like #6488 is solving the same issue as this. Is this still needed? (I forgot about this PR when making my fix there 😅) |
Description
Adds fallback to
viteResolvelogic to just return absolute ids iftryNodeResolvedoesn't return a match.Astro's test suite is down to a single failure with this change.
Additional context
Astro is attempting to upgrade to
vite@2.7.xbut we've been hitting failures in CI. Because Vite is hookingrequirefor SSR, all resolution is running through Vite for these tests.This PR modifies still runs
tryNodeResolve, but if a Vite-specific match is not found and the path is already absolute, we just fallback to the absolute path.What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).