Skip to content

Codegen leaves one folder per library in $TMPDIR on every pod install and Xcode build: generateCode never removes its mkdtempSync folder #60057

Closed

Description

@YevheniiKotyrlo

Description

Every run of scripts/generate-codegen-artifacts.js, which pod install and Xcode's [CP-User] Generate Specs phase both run, leaves one folder per codegen library in the system temp folder ($TMPDIR on macOS), named after the library (AppSpecsXXXXXX, safeareacontextXXXXXX), each holding a copy of that library's generated code. Nothing removes them, so they add up with every pod install and every build.

On main (4a82359), generateCode creates the folder with fs.mkdtempSync(path.join(os.tmpdir(), libraryName)), generates into its out/, copies that to the output folder with cpSyncRecursiveIfChanged, and returns without removing it. The file is the same in 0.88.1.

On a Mac with React Native 0.88.1 (macOS 27.2.1, Xcode 27.2, CocoaPods 1.17.0), one App Store build of an app with eleven codegen libraries left eleven folders from pod install and eleven more from xcodebuild archive, 12 KB to 1.3 MB each, and four days of builds had left 263 of them in that $TMPDIR.

Expected: the temporary folder is gone once generateCode has copied its files, whether generation succeeds or throws, and the output folder gets the same files as today.

Steps to reproduce

  1. Clone the reproducer below. ReproducerApp/package.json declares one app-level codegen library, AppSpecs, whose spec is ReproducerApp/specs/NativeSample.ts.
  2. In ReproducerApp, run yarn install, then node repro.js. It runs react-native/scripts/generate-codegen-artifacts.js --path . --outputPath <output> --targetPlatform ios, the command Xcode's Generate Specs phase runs, with TMPDIR, TEMP and TMP pointed at an empty folder, and lists that folder after the codegen exits. It exits 1 while the codegen leaves anything there, 0 once it leaves nothing.
  3. Expected: the folder is empty. Actual: it holds one folder per codegen library:
    TMPDIR after the run holds 2 entries
      AppSpecsgxi4vl (3 files)
      safeareacontextEGhhho (14 files)
    DEFECT: codegen left 2 temporary folder(s) in TMPDIR after it exited
    

React Native Version

0.88.1

Affected Platforms

Build - MacOS, Build - Windows

Areas

Codegen

Output of npx @react-native-community/cli info

System:
  OS: Windows 11 10.0.26300
  CPU: "(32) x64 AMD Ryzen 9 9950X3D 16-Core Processor          "
  Memory: 139.30 GB / 255.67 GB
Binaries:
  Node:
    version: 26.12.1
    path: C:\Program Files\nodejs\node.EXE
  npm:
    version: 12.2.1
    path: C:\Program Files\nodejs\npm.CMD

Stacktrace or Logs

react-native 0.88.1, node v26.12.1, win32 10.0.26300 x64
TMPDIR, TEMP and TMP set to an empty folder
$ node react-native/scripts/generate-codegen-artifacts.js --path . --outputPath <output> --targetPlatform ios
  [Codegen] Generating Native Code for AppSpecs - ios
  [Codegen] Generated artifacts: <output>\build\generated\ios\ReactCodegen
  [Codegen] Generating Native Code for safeareacontext - ios
  [Codegen] Generated artifacts: <output>\build\generated\ios\ReactCodegen
codegen exited 0 and wrote 2 files to <output>/build/generated/ios/ReactCodegen/AppSpecs
TMPDIR after the run holds 2 entries
  AppSpecsgxi4vl (3 files)
  safeareacontextEGhhho (14 files)
DEFECT: codegen left 2 temporary folder(s) in TMPDIR after it exited

MANDATORY Reproducer

https://github.com/YevheniiKotyrlo/rn-codegen-tmpdir-repro

Screenshots and Videos

No response

Activity

  1. added a commit that references this issue on Nov 17, 2026
    6a695d8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions