-
-
Notifications
You must be signed in to change notification settings - Fork 7.5k
fix(ssr): viteResolve fallback to absolute id
#6126
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| importer: string, | ||
| options = resolveOptions | ||
| ) => { | ||
| const resolved = tryNodeResolve(id, importer, options, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
| // absolute fs paths | |
| if (path.isAbsolute(id) && (res = tryFsResolve(id, options))) { | |
| isDebug && debug(`[fs] ${colors.cyan(id)} -> ${colors.dim(res)}`) | |
| return res | |
| } |
| if (!resolved) { | ||
| if (path.isAbsolute(id)) { | ||
| return id | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
[email protected]but 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).