Description
Description
I have a brownfield React Native setup where I have enabled New Architecture and am now trying to write a Turbo Native Module as per the official documentation. However, I am encountering the following error when launching the React Fragment:
Invariant Violation: TurboModuleRegistry.getEnforcing(...): 'NativeLocalStorage' could not be found.
Verify that a module by this name is registered in the native binary.
Project Structure
I have a multi-module Android project structured as follows:
react-native-brownfield-example/
│── app/ # Native Android app module
│ ├── MainApplication.kt
│ ├── MainActivity.kt
│ ├── build.gradle.kts
│
│── feature/ # Modularized feature components
│ ├── react/ # Contains all React integration code
│ │ ├── NativeLocalStorageModule.kt
│ │ ├── ReactNativeHost
│ │ ├── build.gradle.kts
│
│── reactNative/ # React Native project
│ ├── specs/NativeLocalStorage.ts
│ ├── index.android.js
│ ├── package.json
Reproducible Example
A minimal, reproducible example is available in this repository:
Steps to Reproduce
- Clone the repository:
git clone https://github.com/sanjeevyadavIT/react-native-brownfield-example.git
cd react-native-brownfield-example
git checkout feat/add-native-module
- Install dependencies:
cd reactNative
npm install
cd ..
- Generate codegen artifacts:
./gradlew generateCodegenArtifactsFromSchema
- Open the project in Android Studio and run the app.

- Click "Open React Fragment" in the UI.

- Observe the Invariant Violation error.
Solution provided by Facebook team @cortinico
I raised this same issue facebook/react-native#49246 and @cortinico provided the solution here -> facebook/react-native#49246 (comment)
But the problem with the solution provided by Nicola Corti is (although it works) it adds a @private/react-native-feature
in node_modules
and move all the Android integration code written in feature/react
into $rootProject/reactNative/@node_modules/@private/react-native-feature
but my Actual project has tons of feature module which depends on feature/react
module and some of the class are auto generated using dependency injection that relies on code written in feature/react
, using this solution doesn't work
Help Needed
✅ Is there any changes needed in my brownfield setup for android multi-module project?
✅ How can I correctly register my Turbo Native Module within a multi-module Android project?