Skip to content

feat(ssr): support import.meta.resolve in module runner #20260

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

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sapphi-red
Copy link
Member

Description

This PR adds import.meta.resolve support to the module runner.

I recently encountered a similar problem and came up with this idea, so I implemented to see if it works 😀

This approach only works in Node as it relies on 1. module customization hooks, 2. the second parameter of import.meta.resolve. But I don't think there's a way to avoid "2" and then that limitation is impossible to avoid. Because of "2", vitest-dev/vitest#5188 only works in Node as well.

The upside of this approach compared to vitest-dev/vitest#5188 is that this approach does not require users to pass --experimental-import-meta-resolve.

refs vitest-dev/vitest#6953
refs vitest-dev/vitest#5188

@sapphi-red sapphi-red requested a review from hi-ogawa June 21, 2025 11:35
@sapphi-red sapphi-red added p2-nice-to-have Not breaking anything but nice to have (priority) feat: ssr labels Jun 21, 2025
Copy link
Collaborator

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat idea!

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jul 7, 2025

/ecosystem-ci run

Copy link

pkg-pr-new bot commented Jul 7, 2025

Open in StackBlitz

npm i https://pkg.pr.new/vite@20260

commit: 2c32c86

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on b014a94: Open

suite result latest scheduled
histoire failure failure
nuxt failure success
react-router failure failure
vite-environment-examples failure success
vike failure failure
vite-plugin-rsc success undefined undefined
vite-plugin-cloudflare failure success
waku success failure

analogjs, astro, laravel, ladle, quasar, sveltekit, storybook, one, qwik, unocss, rakkas, vite-plugin-pwa, marko, vite-plugin-svelte, vite-setup-catalogue, vite-plugin-vue, vite-plugin-react, vuepress, vitest, vitepress

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jul 7, 2025

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

📝 Ran ecosystem CI on 759248a: Open

suite result latest scheduled
histoire failure failure
react-router failure failure
vike failure failure
vite-plugin-cloudflare failure success
vite-plugin-rsc success undefined undefined
waku success failure

nuxt, analogjs, one, quasar, astro, marko, laravel, ladle, qwik, storybook, vite-environment-examples, unocss, vite-plugin-react, vite-plugin-svelte, rakkas, vite-plugin-pwa, vite-plugin-vue, vite-setup-catalogue, vitest, sveltekit, vuepress, vitepress

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Jul 8, 2025

Cloudflare is still failing. I don't think this is breaking the fundamental behavior, but probably they have strict check which don't expect import("node:module") to be called. I don't think they can implement import.meta.resolve properly anyways, so maybe this should be opt-in as ModuleRunnerOptions?

sapphi-red and others added 2 commits July 8, 2025 15:31
Co-authored-by: graphite-app[bot] <96075541+graphite-app[bot]@users.noreply.github.com>
@sapphi-red
Copy link
Member Author

I added a createImportMeta to control the import.meta object creation. This should allow the downstream to control the import.meta object easier.

@sapphi-red
Copy link
Member Author

/ecosystem-ci run

@vite-ecosystem-ci
Copy link

Copy link
Collaborator

@hi-ogawa hi-ogawa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@sapphi-red sapphi-red added this to the 7.1 milestone Jul 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: ssr p2-nice-to-have Not breaking anything but nice to have (priority) trigger: preview
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants