Skip to content

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
Contributor

@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
Contributor

hi-ogawa commented Jul 7, 2025

/ecosystem-ci run

@pkg-pr-new
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
Contributor

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
Contributor

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
Contributor

@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
@sapphi-red sapphi-red merged commit 62835f7 into vitejs:main Jul 28, 2025
17 checks passed
@sapphi-red sapphi-red deleted the feat/ssr-support-import-meta-resolve-in-module-runner branch August 6, 2025 03:40
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