-
-
Notifications
You must be signed in to change notification settings - Fork 6.1k
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
fix(runner): resolve and normalize absolute path in fetchModule
#18361
base: main
Are you sure you want to change the base?
Conversation
Run & review this pull request in StackBlitz Codeflow. |
bb8c402
to
5e8e7ec
Compare
fetchModule
fetchModule
|
dynamicAbsoluteFull: await import(path.join( | ||
...process.platform === 'win32' ? ['/@fs'] : [], | ||
import.meta.dirname, "simple.js" | ||
)), |
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.
After the change, for Windows, import("C:/...")
doesn't work but probably this behavior hasn't changed from v5? (Also node doesn't support it either as they require import("file://...")
for windows path)
I think I added this test case in #17422 saying it's broken in v6, but maybe it was already broken on v5 if I tested it on Windows 😅
packages/vite/src/node/ssr/runtime/__tests__/fixtures/dynamic-import.js
Outdated
Show resolved
Hide resolved
@@ -16,7 +16,7 @@ export function normalizeAbsoluteUrl(url: string, root: string): string { | |||
// /root/id.js -> /id.js |
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.
I guess the addition of resolveId
in fetchModule
makes this irrelevant. The only downside is the additional call to the server if the entry point is not normalized, but it was already imported.
If we move this to the environment, then maybe this whole function can be removed, which also makes it so the root
is not required anymore
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.
Okay, I moved everything to fetchModule
including file://
handling. It looks like this works, but the behavior of file://
might be actually different from browser and v5 since Astro is relying on userland plugin #17369 (comment)
(though In my opinion, supporting file://
out of the box seems nice to have anyways)
/ecosystem-ci run |
📝 Ran ecosystem CI on
✅ analogjs, histoire, ladle, laravel, marko, nuxt, previewjs, quasar, qwik, rakkas, redwoodjs, storybook, vite-environment-examples, vite-plugin-pwa, vite-plugin-react, vite-plugin-react-swc, vite-plugin-svelte, vite-plugin-vue, vite-setup-catalogue, vitepress, vuepress |
Description
Not so confident that this is a proper fix nor the issue needs fix, but I'm thinking about what would require to support #18223 and hopefully it helps deciding the fate of the issue (bug or wontfix).
One thing I noticed that it looks possible to dedupe/normalize
/abs-path-to/src/etc -> /src/etc
on server side (fetchModule
) and module identity is still kept intact on runner side. ForFetchModuleResult.cache
detection, I replacedgetModuleByUrl
withensureEntryFromUrl
and I'm wondering what's the downside of this.todo
file://
support