From 238bd2452ec0150d37d8f2ee58452be0181d02a6 Mon Sep 17 00:00:00 2001 From: Alex Hunt Date: Wed, 4 Mar 2026 09:23:50 -0800 Subject: [PATCH] Add error when running build script after prepack (#55914) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55914 Introduce a clear error message if running `yarn build` again after `yarn prepack` (which will have applied the `"publishConfig"` field to each `package.json`, just ahead of publishing to npm). This state should never happen in CI or local dev, but can occur if repeat-running `yarn test-release-local` without `yarn test-release-local-clean`. Introducing a validation error is preferable over making this idempotent (logic would be complex + fragile) for this rare + out-of-design edge case. Changelog: [Internal] Reviewed By: alanleedev Differential Revision: D95215735 fbshipit-source-id: 5a9be44f0d0ae1f2721eed2b11088466a4ff7f72 --- scripts/build/build.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/scripts/build/build.js b/scripts/build/build.js index 9ff364c58c6..c8b670a8c0e 100644 --- a/scripts/build/build.js +++ b/scripts/build/build.js @@ -85,6 +85,10 @@ async function build() { async function buildPackage(packageName /*: string */, prepack /*: boolean */) { try { + process.stdout.write( + `${packageName} ${styleText('dim', '.').repeat(72 - packageName.length)} `, + ); + const {emitTypeScriptDefs} = getBuildOptions(packageName); const entryPoints = await getEntryPoints(packageName); @@ -98,10 +102,6 @@ async function buildPackage(packageName /*: string */, prepack /*: boolean */) { !entryPoints.has(file.replace(/\.js$/, '.flow.js')), ); - process.stdout.write( - `${packageName} ${styleText('dim', '.').repeat(72 - packageName.length)} `, - ); - // Build regular files for (const file of files) { await buildFile(path.normalize(file), { @@ -299,6 +299,15 @@ async function getEntryPoints( continue; } + if (target.startsWith('./' + BUILD_DIR + '/')) { + throw new Error( + `Found ./${BUILD_DIR}/* entry in package.json exports for ` + + `${packageName}. This is either a misconfiguration, or the ` + + `prepack script was previously run and the package.json state ` + + `is dirty. Please re-run against a clean working copy.`, + ); + } + if (target.includes('*')) { console.warn( `${styleText('yellow', 'Warning')}: Encountered subpath pattern ${subpath}` +