Skip to content

Fix: Remove NodeJS dependency for get-virtual-routes.ts#3267

Merged
kdaviduik merged 6 commits intoShopify:mainfrom
darintanakaFN:fix-get-virtual-routes
Jan 13, 2026
Merged

Fix: Remove NodeJS dependency for get-virtual-routes.ts#3267
kdaviduik merged 6 commits intoShopify:mainfrom
darintanakaFN:fix-get-virtual-routes

Conversation

@darintanakaFN
Copy link
Copy Markdown
Contributor

WHY are these changes introduced?

Currently the file packages/hydrogen/src/vite/get-virtual-routes.ts uses NodeJS specific functions to get the virtual routes (graphiql, subrequest profiler, etc).

When the hydrogenRoutes function is called during the Hydrogen build process if the current execution environment is in Mini-Oxygen or Cloudflare an error is thrown which prevents the build from succeeding

node_modules/@shopify/hydrogen/dist/development/get-virtual-routes-6PVSMJPH.js:1:9                                                                                                                                                                          │
│                                                                                                                                                                                                                                                                                                                                 │
│  1: import { fileURLToPath } from 'url';                                                                                                                                                                                                                                                                                        │
│              ^                                                                                                                                                                                                                                                                                                                  │
│  2: import path from 'path';                                                                                                                                                                                                                                                                                                    │
│  3: import { readdir } from 'fs/promises';                                                                                                                                                                                                                                                                                      │
│                                                                                                                                                                                                                                                                                                                                 │
│                                                                                                                                                                                                                                                                                                                                 │
│  To investigate the issue, examine this stack trace:                                                                                                                                                                                                                                                                            │
│    at js (1:9): "fileURLToPath" is not exported by "__vite-browser-external:url", imported by "node_modules/  

WHAT is this pull request doing?

Removes getVirtualRoutes from get-virtual-routes.ts (this function isn't used anywhere)
Removes all NodeJS imports from get-virtual-routes.ts
Removes unit test for getVirtualRoutes

HOW to test your changes?

Verify unit test packages/hydrogen/src/vite/get-virtual-routes.test.ts is passing

I have a test npm package with these changes you can add this package as a depedency like below:

...
"@shopify/hydrogen": "https://gitpkg.vercel.app/darintanakaFN/hydrogen/packages/hydrogen?main",
...

in a test hydrogen react router 7 project.

Verify shopify hydrogen NODE_ENV=development shopify hydrogen dev --codegen builds successfully
Verify NODE_ENV=test npm run build && shopify hydrogen preview builds successfully

Checklist

  • I've read the Contributing Guidelines
  • I've considered possible cross-platform impacts (Mac, Linux, Windows)
  • (N/A) I've added a changeset if this PR contains user-facing or noteworthy changes
  • I've added tests to cover my changes
  • (N/A) I've added or updated the documentation

@darintanakaFN darintanakaFN requested a review from a team as a code owner October 17, 2025 00:44
@darintanakaFN
Copy link
Copy Markdown
Contributor Author

I have signed the CLA!

@benjaminsehl
Copy link
Copy Markdown
Member

Great PR at first glance, thanks @darintanakaFN for submitting this — we'll have a look at this early week and let you know of any issues (or else merge). New release coming soon, so assuming all good, will make sure to have this issue fixed.

@darintanakaFN
Copy link
Copy Markdown
Contributor Author

Great PR at first glance, thanks @darintanakaFN for submitting this — we'll have a look at this early week and let you know of any issues (or else merge). New release coming soon, so assuming all good, will make sure to have this issue fixed.

Sounds good! Thanks for the response

@kdaviduik kdaviduik requested a review from a team as a code owner January 13, 2026 04:29
@shopify
Copy link
Copy Markdown
Contributor

shopify Bot commented Jan 13, 2026

Oxygen deployed a preview of your fix-get-virtual-routes branch. Details:

Storefront Status Preview link Deployment details Last update (UTC)
Skeleton (skeleton.hydrogen.shop) ✅ Successful (Logs) Preview deployment Inspect deployment January 13, 2026 4:30 AM

Learn more about Hydrogen's GitHub integration.

Copy link
Copy Markdown
Contributor

@kdaviduik kdaviduik left a comment

Choose a reason for hiding this comment

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

I added a missing changeset, other than that LGTM! Thanks Darin!

@kdaviduik kdaviduik merged commit 6d22e45 into Shopify:main Jan 13, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants