Skip to content

Conversation

@darintanakaFN
Copy link

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
Author

I have signed the CLA!

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.

1 participant