Skip to content
useffect.sh
Book 30 min with a senior
Architecture

Codegen

React Native’s build-time tool that generates the native glue (C++, Java, Objective-C++) from TypeScript or Flow spec files.

Definition

Codegen is the React Native tool that generates, at build time, the repetitive native code needed by Turbo Modules and Fabric Native Components. It crawls the project starting from the directory named in the codegenConfig key of package.json, reads spec files written in TypeScript or Flow, and emits shared C++ plus Java for Android and Objective-C++ for iOS. The generated code acts as a typed interface: the native implementation must match it or the build fails. Codegen replaces the hand-written module signatures and prop descriptors the old architecture required, where nothing checked that JavaScript and native agreed. It runs automatically on every Android build (a Gradle task) and during pod install on iOS (a script phase), but you can also invoke it by hand, through the Gradle task or the Codegen CLI, to inspect the output while developing a module.

In a real app

In a project, Codegen is configured in package.json under codegenConfig: a name, a type (modules, components, or all), a jsSrcsDir, and per-platform options such as javaPackageName or modulesProvider. An app can declare its own config for local modules too. Generated files land under ios/build/generated/ios and android/app/build/generated/source/codegen; they are not committed, and a .gitignore that lets them through is a warning sign.

The frequent errors are spec parsing errors, not logic errors. Codegen accepts only a subset of TypeScript: no arbitrary unions, no generics, Promise<T> with a serializable T. An import type pointing outside jsSrcsDir passes lint but fails the native build, often with a message about a generated file nobody wrote. When pod install breaks on a third-party library after an upgrade, it is often that library’s spec no longer matching the bundled Codegen version.

To debug, npx react-native codegen (or the generateCodegenArtifactsFromSchema Gradle task) regenerates without building the whole app. Nitro Modules ships its own generator, Nitrogen, which follows the same idea but reads richer TypeScript interfaces.

Our services on this

Sources

All 35 glossary terms

One of these is blocking your app?

30 minutes with a senior to look at the problem in your code. Free.