Skip to content

build: prevent Oxygen deploy OOM on large storefronts (disable prod sourcemaps + doc heap fix) - #444

Closed
paul-phan wants to merge 1 commit into
mainfrom
fix/build-oom-guard
Closed

build: prevent Oxygen deploy OOM on large storefronts (disable prod sourcemaps + doc heap fix)#444
paul-phan wants to merge 1 commit into
mainfrom
fix/build-oom-guard

Conversation

@paul-phan

Copy link
Copy Markdown
Member

Why

A client storefront built on this theme hit FATAL ERROR: JavaScript heap out of memory (exit 134) during the Oxygen deploy. The production build peaked above the CI runner's default Node heap (~2GB), so the deploy died before uploading a complete build. The environment then served HTML referencing client JS assets that were never published, and the storefront rendered blank (all oxygen-v2/.../assets/*.js returned 404).

To avoid other clients hitting the same wall on large storefronts, harden the base theme.

Changes

  1. vite.config.tsbuild.sourcemap: false. Sourcemap generation is a major memory driver during the production build; disabling it lowers peak memory with no runtime cost.
  2. README.md — document the heap fix (NODE_OPTIONS: --max-old-space-size=8192 on the Oxygen deploy step) for storefronts large enough to still OOM. The deploy workflow is generated per-storefront by Shopify, so this can't live in the theme repo, but the note tells clients exactly where to add it.

Notes

  • manualChunks splitting is already present in this config and is kept.
  • No behavior change at runtime; sourcemaps were only used for build-time debugging.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 603c75a6f7

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread vite.config.ts
// Disable sourcemaps in the production build. Sourcemap generation is a
// major memory driver and can push large storefronts past the CI runner's
// default Node heap (~2GB), causing OOM (exit 134) during Oxygen deploys.
sourcemap: false,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Disable server sourcemaps in Hydrogen deploys

When the Oxygen workflow uses npx shopify hydrogen deploy, this setting does not disable the expensive server sourcemap build: the installed Shopify CLI's deploy path calls its build helper with sourcemap: true, and that helper passes an inline Vite config for the SSR build (build: { sourcemap: n, ssr: ... }), which takes precedence over vite.config.ts. Large storefront deployments will therefore still generate SSR sourcemaps and can still hit the OOM this commit is meant to avoid unless the deploy uses a custom build command/flag that turns Hydrogen sourcemaps off.

Useful? React with 👍 / 👎.

@paul-phan

Copy link
Copy Markdown
Member Author

Closing in favour of #469.

Built Pilot both ways to check this. The vite.config.ts change here is a no-op:

main (no PR):     dist/server/index.js.map  4,833,304 bytes
this PR applied:  dist/server/index.js.map  4,833,304 bytes
cmp → byte-identical

Two independent reasons:

  1. build.sourcemap already resolves to false on main for both the client and SSR passes. That's Vite's default, so this sets a value to what it already was.
  2. The Shopify CLI overrides the config file anyway. The server build gets sourcemap inline and deploy hardcodes it: await Je({ ..., sourcemap: !0, forceClientSourcemap: d, ... }) in @shopify/cli/dist/chunk-AATUQ2AY.js. Inline config beats the config file in Vite.

The working lever is the CLI's own flag:

Build server output .map files peak RSS
default 6.9 MB 1 1362 MB
SHOPIFY_HYDROGEN_FLAG_SOURCEMAP=false 2.3 MB 0 1136 MB

The NODE_OPTIONS half of the README note was right and carries over to #469. The claim that sourcemaps are 'already disabled in vite.config.ts' did not, since it would send the next person debugging an OOM down the same dead end. The stray empty ## Getting started heading is dropped too.

@paul-phan paul-phan closed this Aug 5, 2026
@paul-phan
paul-phan deleted the fix/build-oom-guard branch August 5, 2026 06:43
paul-phan added a commit that referenced this pull request Aug 5, 2026
Large storefronts hit `JavaScript heap out of memory` (exit 134) during
the Oxygen deploy. The server sourcemap is ~4.6MB, about two thirds of
the server output, and generating it is a major memory driver.

Documents `SHOPIFY_HYDROGEN_FLAG_SOURCEMAP=false` on the deploy step,
alongside the existing `NODE_OPTIONS` heap bump.

Measured on this repo:
  default build:                    dist/server 6.9M, 1 .map, peak RSS 1362MB
  SHOPIFY_HYDROGEN_FLAG_SOURCEMAP=false: dist/server 2.3M, 0 .map, peak RSS 1136MB

Setting `build.sourcemap: false` in vite.config.ts does NOT work: the
Shopify CLI passes `sourcemap` inline to Vite, and inline config
overrides the config file. Verified by building both ways, the server
sourcemap was byte-identical (4,833,304 bytes) with and without it.

Supersedes #444.

Co-authored-by: Paul <paul@pauls-Mac-mini-2.local>
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