Skip to content

Codegen strictly requires deprecated React.ElementRef vs recommended React.ComponentRef #54272

@mikehardy

Description

@mikehardy

Description

https://github.com/search?q=repo%3Afacebook%2Freact-native%20React.ElementRef%3C%3E&type=code

The reproducer is simply seeing that a deprecated React type is strictly required by the codegen parser. I'm posting up a branch where I was working on react-native-google-mobile-ads to remove deprecation and ran into this

Deprecation here, it came in the React types update PR for React v19 - this link is scoped into the lines in the file in blame mode so you may see the deprecation, and the commit that added it along with the PR as desired:
https://github.com/DefinitelyTyped/DefinitelyTyped/blame/master/types/react/index.d.ts#L199-L218

If I patch react-native locally to accept ElementRef or ComponentRef in the codegen parser, it appears to work. I could propose that PR if desired.

Steps to reproduce

  1. add a spec for a native module using new arch that has a method with a ref param and change it from deprecated React.ElementRef to React.ComponentRef
  2. run pod install (which will trigger codegen)

In specific steps:

  1. git clone [email protected]:invertase/react-native-google-mobile-ads
  2. git checkout rn-codegen-fail-repro
  3. yarn install && yarn tests:install
  4. the failure: yarn tests:ios:install:pods (same as cd RNGoogleMobileAdsExample/ios && pod install

witness:


[Codegen] Analyzing /Users/mike/work/invertase/react-native-google-mobile-ads/RNGoogleMobileAdsExample/package.json
[Codegen] Could not find generated autolinking output at: /Users/mike/work/invertase/react-native-google-mobile-ads/RNGoogleMobileAdsExample/ios/build/generated/autolinking/autolinking.json
[Codegen] Searching for codegen-enabled libraries in the app.
[Codegen] The "codegenConfig" field is not defined in package.json. Assuming there is nothing to generate at the app level.
[Codegen] Could not find generated autolinking output at: /Users/mike/work/invertase/react-native-google-mobile-ads/RNGoogleMobileAdsExample/ios/build/generated/autolinking/autolinking.json
[Codegen] Searching for codegen-enabled libraries in the project dependencies.
[Codegen] Found react-native
[Codegen] Found react-native-google-mobile-ads
[Codegen] Found react-native-safe-area-context
[Codegen] Searching for codegen-enabled libraries in react-native.config.js
[Codegen] Processing FBReactNativeSpec
[Codegen] Searching for podspec in the project dependencies.
[Codegen] Processing RNGoogleMobileAdsSpec
[Codegen] Searching for podspec in the project dependencies.
[Codegen] Supported Apple platforms: ios for RNGoogleMobileAdsSpec
[Codegen] Error: The first argument of method recordManualImpression must be of type React.ElementRef<>
[Codegen] Done.

This is triggered by the lines I link above (in the form of a search of this repo, where it shows it will fail for typescript or flow codegen input files

I am selecting 'macOS' as the build platform because ios isn't a choice? That seems odd. It will affect both though.

React Native Version

0.82.1

Affected Platforms

Build - MacOS

Areas

Codegen

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

mike@isabela:~/work/invertase/react-native-google-mobile-ads/RNGoogleMobileAdsExample (update-example-script *+) % npx @react-native-community/cli info
info Fetching system and libraries information...
System:
  OS: macOS 26.0.1
  CPU: (8) arm64 Apple M2
  Memory: 98.05 MB / 16.00 GB
  Shell:
    version: 3.2.57
    path: /bin/bash
Binaries:
  Node:
    version: 22.14.0
    path: /Users/mike/.nvm/versions/node/v22.14.0/bin/node
  Yarn:
    version: 4.10.3
    path: /Users/mike/.nvm/versions/node/v22.14.0/bin/yarn
  npm:
    version: 11.6.2
    path: /Users/mike/work/invertase/react-native-google-mobile-ads/node_modules/.bin/npm
  Watchman:
    version: 2025.10.20.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.16.2
    path: /Users/mike/.asdf/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 25.0
      - iOS 26.0
      - macOS 26.0
      - tvOS 26.0
      - visionOS 26.0
      - watchOS 26.0
  Android SDK:
    API Levels:
      - "28"
      - "29"
      - "30"
      - "31"
      - "33"
      - "34"
      - "35"
      - "36"
      - "36"
    Build Tools:
      - 28.0.3
      - 29.0.2
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 33.0.2
      - 34.0.0
      - 35.0.0
      - 36.0.0
      - 36.1.0
    System Images:
      - android-23 | ARM 64 v8a
      - android-24 | Google APIs ARM 64 v8a
      - android-24 | Google Play Intel x86 Atom
      - android-25 | Google APIs ARM 64 v8a
      - android-26 | Google APIs ARM 64 v8a
      - android-27 | Google APIs ARM 64 v8a
      - android-28 | Google APIs ARM 64 v8a
      - android-29 | Google APIs ARM 64 v8a
      - android-34 | Desktop ARM 64 v8a
      - android-35 | Google Play ARM 64 v8a
      - android-35 | Pre-Release 16 KB Page Size Google APIs ARM 64 v8a
      - android-36.1 | Google APIs ARM 64 v8a
      - android-36.1 | Google Play ARM 64 v8a
    Android NDK: Not Found
IDEs:
  Android Studio: 2025.1 AI-251.27812.49.2514.14217341
  Xcode:
    version: 26.0.1/17A400
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 21.0.8
    path: /Library/Java/JavaVirtualMachines/temurin-21.jdk/Contents/Home/bin/javac
  Ruby:
    version: 3.4.6
    path: /Users/mike/.asdf/shims/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 20.0.0
    wanted: 20.0.0
  react:
    installed: 19.1.1
    wanted: 19.1.1
  react-native:
    installed: 0.82.1
    wanted: 0.82.1
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: false
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

[Codegen] Error: The first argument of method recordManualImpression must be of type React.ElementRef<>

MANDATORY Reproducer

https://github.com/invertase/react-native-google-mobile-ads#rn-codegen-fail-repro

Screenshots and Videos

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: AttentionIssues where the author has responded to feedback.Needs: ReproThis issue could be improved with a clear list of steps to reproduce the issue.PartnerType: New ArchitectureIssues and PRs related to new architecture (Fabric/Turbo Modules)p: contributor

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions