Fix npm package worker resolution in Vite v6 / 2025.1.3+#2840
Fix npm package worker resolution in Vite v6 / 2025.1.3+#2840juanpprieto wants to merge 23 commits intomainfrom
Conversation
|
Oxygen deployed a preview of your
Learn more about Hydrogen's GitHub integration. |
|
/snapit |
|
/snapit |
|
🫰✨ Thanks @juanpprieto! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/cli-hydrogen": "0.0.0-snapshot-20250404162914",
"@shopify/hydrogen": "0.0.0-snapshot-20250404162914",
"@shopify/mini-oxygen": "0.0.0-snapshot-20250404162914"
|
|
/snapit |
|
🫰✨ Thanks @juanpprieto! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/cli-hydrogen": "0.0.0-snapshot-20250408190305",
"@shopify/hydrogen": "0.0.0-snapshot-20250408190305",
"@shopify/mini-oxygen": "0.0.0-snapshot-20250408190305"
|
|
/snapit |
There was a problem hiding this comment.
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (1)
packages/hydrogen/src/vite/plugin.ts:64
- The condition 'workerd' may be a typo unless it is intentionally targeting a specific non-standard environment. Please confirm if 'workerd' is required or if it should be removed.
conditions: ['workerd', 'worker'], // Recommended earlier, ideally combined with these settings
|
🫰✨ Thanks @juanpprieto! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/cli-hydrogen": "0.0.0-snapshot-20250408212515",
"@shopify/hydrogen": "0.0.0-snapshot-20250408212515"
|
|
/snapit |
|
🫰✨ Thanks @juanpprieto! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/cli-hydrogen": "0.0.0-snapshot-20250408225709",
"@shopify/hydrogen": "0.0.0-snapshot-20250408225709",
"@shopify/mini-oxygen": "0.0.0-snapshot-20250408225709"
|
| ssr: { | ||
| noExternal: true, | ||
| target: 'webworker', | ||
| resolve: { |
|
/snapit |
|
🫰✨ Thanks @juanpprieto! Your snapshots have been published to npm. Test the snapshots by updating your "@shopify/cli-hydrogen": "0.0.0-snapshot-20250414204700",
"@shopify/hydrogen": "0.0.0-snapshot-20250414204700",
"@shopify/mini-oxygen": "0.0.0-snapshot-20250414204700"
|
There was a problem hiding this comment.
Hey 👋 I mentioned this to Bret already but here are some thoughts:
Vite 6 changed how resolve.conditions work. Here's the migration guide: https://vite.dev/guide/migration.html#default-value-for-resolve-conditions
To keep the same behavior, I think you would need to add resolve.conditions: ['worker', 'workerd', ...defaultClientConditions] and ssr.resolve.conditions: ['worker', 'workerd', ...defaultClientConditions], doing import {defaultClientConditions} from 'vite'.
workerd is likely not required (it was added just in case), but worker should still be added in front of other conditions. This will make sure you end up importing the "worker" entry point for libraries that specify it, like here (otherwise it would likely get browser.import, which is a different entry file).
For the record, Vite versions before 6 were using resolve.conditions also as ssr.resolve.conditions and adding the default values automatically (module, browser, prod/dev, etc.). However, Vite 6 requires you to do all of this manually as mentioned above.
|
Replaced by #2863 |

Context:
https://shopifypartners.slack.com/archives/C02F94JC3QC/p1743413107901139
sanity-io/hydrogen-sanity#116
sanity-io/visual-editing#1085
Vite 6 (2025.1.3+) seems to have a different more strict NPM module resolution logic for worker exports. This PR aims to fix this by adding an additional resolve conditions for workers in the SSR option.
Looking for feedback
For those having this issue with
2025.1.3+Could you try this draft mini-oxygen version?
`"@shopify/mini-oxygen": "0.0.0-snapshot-20250408225709"`P.S - when tophating a codebase with
hydrogen-sanityyou might need tonpm i -forcebecause the sanity does not allow snapshot versions of hydrogen.Important
make sure you comment out @nkgentile previous vite.config solution if you implemented it to make sure the test results are not skewed
🎩 Top** hat instructions: