hydrogen: [VITE] Missing dependencies after running setup vite command

What is the location of your example repository?

No response

Which package or tool is having this issue?

Hydrogen

What version of that package or tool are you using?

“@shopify/hydrogen”: “~2024.1.3”

What version of Remix are you using?

“@remix-run/node”: “^2.8.0”

Steps to Reproduce

  1. Create a new Hydrogen project using npm create @shopify/hydrogen@latest
  2. Run vite setup command npx shopify hydrogen setup vite
  3. Launch dev server npm run dev

Expected Behavior

Hydrogen app should launch correctly.

Actual Behavior

Missing dependencies:

Failed to resolve dependency: set-cookie-parser, present in 'ssr.optimizeDeps.include'
Failed to resolve dependency: cookie, present in 'ssr.optimizeDeps.include'
Failed to resolve dependency: content-security-policy-builder, present in 'ssr.optimizeDeps.include'

ReferenceError: exports is not defined

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (12 by maintainers)

Most upvoted comments

I was able to reproduce this finally in our demo-store. The problem is not related to Hydrogen, though, so we can’t fix much here I think.

The issue is that Vite tries to find dependencies to optimize in node_modules/* but PNPM moves most of the dependencies to node_modules/.pnpm/node_modules/* so Vite can’t find them. More info here.

Try adding the following to your .npmrc file to force hoisting these dependencies that Vite must optimize for the worker runtime (from pnpm docs):

public-hoist-pattern[]=cookie
public-hoist-pattern[]=set-cookie-parser
public-hoist-pattern[]=content-security-policy-builder

You might need to add more dependencies, depending on what you are using in your project.

Yeah sorry I didn’t try to remove node_modules. It works perfectly now, thanks!