Shopify / hydrogen

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

Vite Shopify Hydrogen Deploy Hardcodes the Removal of Client Source Maps #2474

Closed gugges closed 2 weeks ago

gugges commented 2 weeks ago

What is the location of your example repository?

https://github.com/Shopify/hydrogen/blob/0933f812f7155fa07e87c655ea163d0c9b7c462b/packages/cli/src/commands/hydrogen/build.ts#L181

Which package or tool is having this issue?

CLI

What version of that package or tool are you using?

2024.7.4

What version of Remix are you using?

2.11.2

Steps to Reproduce

We are in the middle of upgrading our Remix/Hydrogen store to Vite and stumbled upon an issue with our Sentry integration. After some digging, we notice that there is no way to get our client source maps to Sentry. This prevents Sentry from properly tracking crashes that happen in the client, and the stack trace remains minified.

The root issue is that the client source maps are not generated by shopify hydrogen build since they are hard coded to false in the cli build step here: https://github.com/Shopify/hydrogen/blob/0933f812f7155fa07e87c655ea163d0c9b7c462b/packages/cli/src/commands/hydrogen/build.ts#L181

Expected Behavior

The caller of shopify hydrogen deploy should be given a flag or env var to set to override the hard coding of the client source map to false on deploys. We are able to do that with shopify hydrogen deploy --build-command="remix vite:build", but when doing so, we lose the other optimizations the Shopify team has made as part of the standard shopify hydrogen build functionality. So ideally we do not override the build command.

As an aside, when we do use the remix vite:build we are not seeing the source maps uploaded anyway, but we have still added an extra fail safe by cleaning up our source map files before Shopify uploads them to Oxygen with the following setup:

    sentryVitePlugin({
      org: "***",
      project: "***",
      authToken: ***,
      sourcemaps: {
        filesToDeleteAfterUpload: ["dist/**/*.map"],
      },
    }),

Actual Behavior

Source maps are not generated for the client code when running shopify hydrogen deploy or shopify hydrogen build

frandiox commented 2 weeks ago

Implemented here: https://github.com/Shopify/hydrogen/pull/2477

filesToDeleteAfterUpload: ["dist/*/.map"],

You might want to only delete dist/client/**/*.map and keep dist/server, since that's useful in the Hydrogen Admin panel to see error logs.