react/scripts/rollup
Henry Q. Dineen ed1351c4fb
[compiler] improve zod v3 backwards compat (#34877)
## Summary

When upgrading to `babel-plugin-react-compiler@1.0.0` in a project that
uses `zod@3` we are running into TypeScript errors like:

```
node_modules/babel-plugin-react-compiler/dist/index.d.ts:435:10 - error TS2694: Namespace '"/REDACTED/node_modules/zod/v3/external"' has no exported member 'core'.

435     }, z.core.$strip>>>;
             ~~~~
```

This problem seems to be related to
d6eb735938, which introduced zod v3/v4
compatibility. Since `zod` is bundled into the compiler source this does
not cause runtime issues and only manifests as TypeScript errors. My
proposed solution is this PR is to use zod's [subpath versioning
strategy](https://zod.dev/v4/versioning?id=versioning-in-zod-4) which
allows you to support v3 and v4 APIs on both major versions.

Changes in this PR include:

- Updated `zod` import paths to `zod/v4`
- Bumped min `zod` version to `^3.25.0` for zod which guarantees the
`zod/v4` subpath is available.
- Updated `zod-validation-error` import paths to
`zod-validation-error/v4`
- Bumped min `zod-validation-error ` version to `^3.5.0` 
- Updated `externals` tsup configuration where appropriate. 

Once the compiler drops zod v3 support we could optionally remove the
`/v4` subpath from the imports.

## How did you test this change?

Not totally sure the best way to test. I ran `NODE_ENV=production yarn
workspace babel-plugin-react-compiler run build --dts` and diffed the
`dist/` folder between my change and `v1.0.0` and it looks correct. We
have a `patch-package` patch to workaround this for now and it works as
expected.

```diff
diff --git a/node_modules/babel-plugin-react-compiler/dist/index.d.ts b/node_modules/babel-plugin-react-compiler/dist/index.d.ts
index 81c3f3d..daafc2c 100644
--- a/node_modules/babel-plugin-react-compiler/dist/index.d.ts
+++ b/node_modules/babel-plugin-react-compiler/dist/index.d.ts
@@ -1,7 +1,7 @@
 import * as BabelCore from '@babel/core';
 import { NodePath as NodePath$1 } from '@babel/core';
 import * as t from '@babel/types';
-import { z } from 'zod';
+import { z } from 'zod/v4';
 import { NodePath, Scope } from '@babel/traverse';
 
 interface Result<T, E> {
```

Co-authored-by: Henry Q. Dineen <henryqdineen@gmail.com>
2025-10-16 09:46:55 -07:00
..
externs Replay Client Actions After Hydration (#26716) 2023-04-25 10:22:20 -04:00
plugins [Fizz] Share code between inline and external runtime (#33066) 2025-05-01 14:25:10 -04:00
shims Add flow suppression for Constant Condition rollout (#34243) 2025-08-20 18:24:01 -04:00
validate [Flight] Add DebugInfo for Bundler Chunks (#34226) 2025-08-18 11:34:00 -04:00
build-all-release-channels.js Apply build script changes for RN to main (#34640) 2025-09-29 20:40:24 -04:00
build.js Stop treating all Node.js builtins implicitly as externals (#34249) 2025-08-25 09:39:56 +02:00
bundles.js [compiler] improve zod v3 backwards compat (#34877) 2025-10-16 09:46:55 -07:00
forks.js [flags] remove enableRemoveConsolePatches (#32425) 2025-02-24 10:00:22 -05:00
generate-inline-fizz-runtime.js [Fizz] Wrap revealCompletedBoundaries in a ViewTransitions aware version (#33293) 2025-05-17 18:18:24 -04:00
modules.js [Flight] Source Map Actions in Reference Node Loader Transforms (#30755) 2024-08-21 09:52:17 -04:00
packaging.js build: add support to the rollup build for building typescript packages (#32393) 2025-02-16 10:38:13 -05:00
stats.js [ci] Cleanup --ci flag 2024-07-29 19:18:03 -04:00
sync.js Fork React Native renderer into FB and OSS bundles (#12625) 2018-04-18 13:16:50 -07:00
utils.js Fixed broken build script --unsafe-partial flag (#22324) 2021-09-15 13:32:09 -04:00
wrappers.js build: add support to the rollup build for building typescript packages (#32393) 2025-02-16 10:38:13 -05:00