Skip to content

Disabling autolinking on iOS selectively in react-native.config.js crashes the app during runtime #51077

Closed

Description

@ismarbesic

Description

Selectively disabling autolinking of a native dependency with components registered in the codegen configuration in react-native.config.js causes builds to crash upon launch on iOS when the new architecture is enabled. This is because the generated RCTThirdPartyComponentsProvider.mm file contains references to the excluded library using NSClassFromString causing the returned NSDictionary from +[RCTThirdPartyComponentsProvider thirdPartyFabricComponents] to be populated with nil values since the classes are not bundled in the native build and therefore crashing the app. This has been confirmed in 0.78.2 and 0.79.2 but probably exists in 0.77.x as well.

Steps to reproduce

  1. Install a library that has the componentProvider field set in the codegen config (see reproducer) and install the iOS pods.
  2. Build the app.
  3. App will crash with an exception (see in the stacktrace or logs section) even though it was built successfully.

React Native Version

0.79.2

Affected Platforms

Runtime - iOS

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

System:
  OS: macOS 15.0.1
  CPU: (10) arm64 Apple M1 Pro
  Memory: 146.59 MB / 32.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.5
    path: ~/.nvm/versions/node/v18.20.5/bin/node
  Yarn:
    version: 1.22.22
    path: /opt/homebrew/bin/yarn
  npm:
    version: 10.8.2
    path: ~/.nvm/versions/node/v18.20.5/bin/npm
  Watchman: Not Found
Managers:
  CocoaPods: Not Found
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 24.0
      - iOS 18.0
      - macOS 15.0
      - tvOS 18.0
      - visionOS 2.0
      - watchOS 11.0
  Android SDK: Not Found
IDEs:
  Android Studio: Not Found
  Xcode:
    version: 16.0/16A242d
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 18.0.2.1
    path: /usr/bin/javac
  Ruby:
    version: 2.7.5
    path: ~/.rvm/rubies/ruby-2.7.5/bin/ruby
npmPackages:
  "@react-native-community/cli":
    installed: 18.0.0
    wanted: 18.0.0
  react:
    installed: 19.0.0
    wanted: 19.0.0
  react-native:
    installed: 0.79.2
    wanted: 0.79.2
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: true
iOS:
  hermesEnabled: true
  newArchEnabled: true

Stacktrace or Logs

{"arguments":["-[__NSPlaceholderDictionary initWithObjects:forKeys:count:]","8"],"format_string":"*** %s: attempt to insert nil object from objects[%lu]","name":"NSInvalidArgumentException","type":"objc-exception","composed_message":"*** -[__NSPlaceholderDictionary initWithObjects:forKeys:count:]: attempt to insert nil object from objects[8]","class":"NSException"}

Last Exception Backtrace:
0   CoreFoundation                	       0x18ffcd2ec __exceptionPreprocess + 164
1   libobjc.A.dylib               	       0x18d451a7c objc_exception_throw + 88
2   CoreFoundation                	       0x18ff0160c -[__NSPlaceholderDictionary initWithObjects:forKeys:count:] + 724
3   CoreFoundation                	       0x18ff0122c +[NSDictionary dictionaryWithObjects:forKeys:count:] + 52
4   XXX                           	       0x1055e1b24 +[RCTThirdPartyComponentsProvider thirdPartyFabricComponents] + 912
5   XXX                           	       0x10559fd24 __54-[RCTAppDependencyProvider thirdPartyFabricComponents]_block_invoke + 28
6   libdispatch.dylib             	       0x197e4b584 _dispatch_client_callout + 16
7   libdispatch.dylib             	       0x197e349a8 _dispatch_once_callout + 32
8   XXX                           	       0x10559fd04 -[RCTAppDependencyProvider thirdPartyFabricComponents] + 124
9   XXX                           	       0x105475bbc -[RCTDefaultReactNativeFactoryDelegate thirdPartyFabricComponents] + 64
10  XXX                           	       0x105476548 -[RCTReactNativeFactory thirdPartyFabricComponents] + 84
11  XXX                           	       0x1054b20d4 -[RCTComponentViewFactory registerComponentIfPossible:] + 308
12  XXX                           	       0x1054b2a64 

MANDATORY Reproducer

https://github.com/ismarbesic/react-native-codegen-selectively-disabled-lib-bug-repro

Screenshots and Videos

No response

Activity

  1. added
    Type: New ArchitectureIssues and PRs related to new architecture (Fabric/Turbo Modules)
    Issue: Author Provided ReproThis issue can be reproduced in Snack or an attached project.
    and removed on May 6, 2025
  2. cortinico commented on May 6, 2025

    @cortinico
    Contributor

    Selectively disabling autolinking of a native dependency with components registered in the codegen configuration in react-native.config.js causes builds to crash upon launch on iOS when the new architecture is enabled

    cc @cipolleschi - Can you check if #51078 solves the issue correctly?

  3. cipolleschi commented on May 6, 2025

    @cipolleschi
    Contributor

    @ismarbesic thanks for opening the issue. I'll have a look at the fix shortly or tomorrow morning. Can I ask why do you need to turn off autolinking for that library? Is iOS not using it at all?

  4. ismarbesic commented on May 6, 2025

    @ismarbesic
    ContributorAuthor

    Thanks for checking it out! The library I added was just an example but we have similar internal use cases where we want to strip away certain libraries under certain conditions but still have functioning builds.

  5. WheelerLee commented on May 7, 2025

    @WheelerLee

    I have a similar issue. My dependencies look like this:

    "dependencies": {
      "react": "19.0.0",
      "react-native": "0.79.2",
      "react-native-safe-area-context": "^5.4.0",
      "react-native-screens": "^4.10.0"
    }

    And the code is as follows:

    function App(): React.JSX.Element {
      return (
        <SafeAreaProvider>
          <Text>Hello World</Text>
        </SafeAreaProvider>
      );
    }

    Everything was working fine until I added my own specs and executed pod install.

    Image

    The issue has been tested and occurs on React Native versions 0.77, 0.78, and 0.79, but version 0.76 works fine.

  6. cipolleschi commented on May 8, 2025

    @cipolleschi
    Contributor

    yeah, so the reason here is that, to maintain backward compatibility, we added a lookup mechanism that searches for the components. @WheelerLee Is your app crashing when opening the RNSModalScreen or the RNScreen? The string after RNScreen is pretty wrong... it should just be RNSScreenView... 😓

  7. ismarbesic commented on May 8, 2025

    @ismarbesic
    ContributorAuthor

    @cipolleschi @cortinico I saw the PR was merged - thanks a lot for reviewing it! Glad we could contribute those changes back for everyone to benefit from.

  8. tux2nicolae commented on Jun 22, 2025

    @tux2nicolae
    Contributor

    We do have the same issue but in a different scenario, on IOS we have two targets, one is our full app and the other is an app clip, inside the app clip we should exclude some libraries to save space due to the size constraints.

    For this to work we use this workaround.

    This used to work until now, but now because of the auto discovery, the components will be found inside the appclip target as well and the app clip will crash, we did not found a solution to exclude some libraries from auto link inside a specific target, there is already a similar request which apparently did not get through

  9. Jigs6720 commented on Jan 20, 2026

    @Jigs6720

    I have a similar issue. My dependencies look like this:

    "dependencies": {
    "react": "19.0.0",
    "react-native": "0.79.2",
    "react-native-safe-area-context": "^5.4.0",
    "react-native-screens": "^4.10.0"
    }
    And the code is as follows:

    function App(): React.JSX.Element {
    return (

    Hello World

    );
    }
    Everything was working fine until I added my own specs and executed pod install.

    Image

    The issue has been tested and occurs on React Native versions 0.77, 0.78, and 0.79, but version 0.76 works fine.

    +1

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