Shopify / hydrogen

Hydrogen lets you build faster headless storefronts in less time, on Shopify.
https://hydrogen.shop
MIT License
1.36k stars 262 forks source link

Build fails when customizing SSR entrypoint due to hardcoded deletion of SSR build `assets/` (chunks) directory #2497

Open serhalp opened 2 weeks ago

serhalp commented 2 weeks ago

What is the location of your example repository?

https://github.com/netlify/hydrogen-template/commit/71145c98d6245d05012fd110bf88ab1c4e83a099

Which package or tool is having this issue?

CLI

What version of that package or tool are you using?

@shopify/cli@3.66.1, @shopify/hydrogen@2024.7.4

What version of Remix are you using?

2.11.2

Steps to Reproduce

  1. Create a Hydrogen site (e.g. with create-hydrogen)
  2. Override Remix's default SSR entrypoint configuration, e.g. to build a Netlify Edge Function
  3. shopify hydrogen build (don't run npm run build; we've changed this as a workaround)

This is a bit vague, so here are some more concrete steps you can actually follow:

  1. Clone https://github.com/netlify/hydrogen-template and checkout commit 71145c98d6245d05012fd110bf88ab1c4e83a099, npm i
  2. Clone https://github.com/netlify/remix-compute and checkout https://github.com/netlify/remix-compute/pull/441, pnpm i && pnpm build:packages, then in the hydrogen template run npm link ../remix-compute/packages/remix-edge-adapter
  3. shopify hydrogen build (don't run npm run build; we've changed this as a workaround)

To provide a bit more context, I work at Netlify and we encountered this while building out support for Hydrogen Vite on our platform. As noted below, we have a workaround, but it isn't ideal and this could bite others in the future.

Expected Behavior

The site builds successfully. (The assumption is that since I'm (or some other Vite plugin is) customizing my SSR entrypoint configuration, I'm (or said other Vite plugin is) responsible for knowing this and handling it from end to end. Other than this one hiccup — and https://github.com/Shopify/hydrogen/issues/2496 — this does seem to work just fine.)

Actual Behavior

The details here will vary depending on the specifics, but if you use the template linked above, you'll get:

Packaging Functions from .netlify/functions-internal directory:
 - remix-server.mjs

✘ [ERROR] Could not resolve "./assets/server-build-BOKKiHSv.js"

This is because for some reason I don't quite grasp the hydrogen CLI build command deletes the assets/ directory from the server build output directory after building. Maybe the command is assuming chunking has been disabled? I'm not really sure, but it seems to be a leaky assumption, perhaps related to the Oxygen platform.

If I comment out this line inside my node_modules, everything works.

For now, we're going to have our Netlify template and docs use remix vite:build instead of shopify hydrogen build as a workaround.

Thanks!

scottdixon commented 2 weeks ago

Another great catch @serhalp! Thanks for the report. Big fans of Netlify over here ❤