From d3de1795f721f7d9d7f10e16eea797833e964fe9 Mon Sep 17 00:00:00 2001 From: Oleksii Bulenok Date: Tue, 11 Aug 2026 13:57:38 +0200 Subject: [PATCH] enable expo experimental tree shaking --- Dockerfile | 4 ++++ babel.config.js | 22 ++++++++++++++++++++++ package.json | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index fff191cc58..f0bab01ceb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,10 @@ ENV CI=1 # use the pnpm version specified in package.json ENV pnpm_config_pm_on_fail=download +# Metro's web export needs far more heap than Node's default (~1GB in the +# container), which crashes the bundle step with a V8 OOM. +ENV NODE_OPTIONS="--max-old-space-size=8192" + # The latest git hash of the preview branch on render.com # https://render.com/docs/docker-secrets#environment-variables-in-docker-builds ARG RENDER_GIT_COMMIT diff --git a/babel.config.js b/babel.config.js index 90abe51c4d..b3875d02ab 100644 --- a/babel.config.js +++ b/babel.config.js @@ -1,3 +1,24 @@ +/** + * React Compiler tags generated nodes with loc = Symbol(GeneratedSource), + * which breaks the structuredClone Metro performs on the AST when + * EXPO_UNSTABLE_TREE_SHAKING is enabled. Strip them after all other + * transforms have run. + */ +const stripSymbolLocs = () => ({ + post(file) { + file.path.traverse({ + enter(path) { + if (typeof path.node.loc === 'symbol') { + path.node.loc = undefined + } + }, + }) + if (typeof file.ast.program.loc === 'symbol') { + file.ast.program.loc = undefined + } + }, +}) + /** * @param {import("@babel/core").ConfigAPI} api * @returns {import("@babel/core").InputOptions} @@ -45,6 +66,7 @@ module.exports = function (api) { : []), ...(api.env('production') ? ['transform-remove-console'] : []), + stripSymbolLocs, 'react-native-worklets/plugin', // NOTE: this plugin MUST be last ], } diff --git a/package.json b/package.json index 132debbf20..31ec7e2e32 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "web": "expo start --web", "use-build-number": "./scripts/useBuildNumberEnv.sh", "use-build-number-with-bump": "./scripts/useBuildNumberEnvWithBump.sh", - "build-web": "expo export --platform web --source-maps && node ./scripts/post-web-build.js", + "build-web": "EXPO_UNSTABLE_METRO_OPTIMIZE_GRAPH=1 EXPO_UNSTABLE_TREE_SHAKING=1 expo export --platform web --source-maps && node ./scripts/post-web-build.js", "build-all": "pnpm intl:build && pnpm use-build-number-with-bump eas build --platform all", "build-ios": "pnpm use-build-number-with-bump eas build -p ios", "build-android": "pnpm use-build-number-with-bump eas build -p android",