Registry / devops / react-native-config

react-native-config

JSON →
library1.6.1jsnpmunverified

react-native-config is a module that provides a straightforward way to expose configuration variables to React Native applications, aligning with the 12 Factor App methodology for configuration. It supports multiple platforms including iOS, Android, macOS, and Windows. The current stable version is 1.6.1, with releases occurring frequently to address platform-specific issues, introduce new architecture support (like Fabric for iOS and Android), and extend compatibility to newer platforms like visionOS. Its key differentiators include broad platform support and a simple `.env` file interface, making it easy to manage environment-specific variables without modifying code. However, it's crucial to understand that it does not obfuscate or encrypt secrets, which is a fundamental limitation for mobile apps; therefore, sensitive keys should not be stored directly in `.env` files. The package emphasizes ease of use for non-sensitive configuration parameters across diverse mobile and desktop platforms supported by React Native.

npm install react-native-config
INSTALL
IMPORT
SIG · REACT-NATIVE-CONFI
R
react-native-config
devopsjavascriptv1.6.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Config
import Config from 'react-native-config';
const Config = require('react-native-config');
Config is the default export containing all environment variables. While CommonJS `require` might work in some setups, modern React Native tooling and module resolution favor ESM `import`. The package ships TypeScript types for type-safe access.

This example demonstrates how to define environment variables in a `.env` file and access them within a React Native component using `react-native-config`. It highlights the basic usage pattern for displaying configuration values and includes a crucial warning about storing sensitive information.

import Config from "react-native-config"; import { useEffect, useState } from 'react'; import { View, Text, StyleSheet } from 'react-native'; const App = () => { const [apiUrl, setApiUrl] = useState(''); const [googleMapsKey, setGoogleMapsKey] = useState(''); useEffect(() => { // Variables from .env are automatically loaded into the Config object // Ensure you have a .env file in your project root, e.g.: // API_URL=https://myapi.com/v1 // GOOGLE_MAPS_API_KEY=your_google_maps_api_key // SENSITIVE_KEY_EXAMPLE=DO_NOT_STORE_SECRETS_DIRECTLY_HERE setApiUrl(Config.API_URL); setGoogleMapsKey(Config.GOOGLE_MAPS_API_KEY); }, []); return ( <View style={styles.container}> <Text style={styles.header}>React Native Config Example</Text> <Text style={styles.label}>API URL:</Text> <Text style={styles.value}>{apiUrl || 'Not set'}</Text> <Text style={styles.label}>Google Maps Key:</Text> <Text style={styles.value}>{googleMapsKey || 'Not set'}</Text> <Text style={styles.warning}> Warning: Do not store sensitive keys in .env for mobile apps as they are not obfuscated. </Text> </View> ); }; const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', padding: 20, backgroundColor: '#f5f5f5', }, header: { fontSize: 24, fontWeight: 'bold', marginBottom: 20, color: '#333', }, label: { fontSize: 16, fontWeight: '600', marginTop: 10, color: '#555', }, value: { fontSize: 16, marginBottom: 5, color: '#007bff', }, warning: { fontSize: 12, color: 'red', marginTop: 30, textAlign: 'center', }, }); export default App;
Debug
Known issues
gotchaSecrets stored in `.env` files are not obfuscated or encrypted when packaged into a mobile app. Malicious users can reverse engineer apps to extract these values.
fix
Design your backend APIs to not rely on client-side secrets, or use a secure vault/backend service for sensitive key management instead of storing them directly in the app's `.env`.
affects: >=1.0.0
breakingFor React Native versions prior to 0.60, autolinking is not available. Manual linking steps for iOS, Android, and Windows are required, which can be complex and error-prone. Windows also requires manual linking for versions below 0.63.
fix
Refer to the `react-native-config` documentation for platform-specific manual linking instructions or upgrade your React Native project to a version that supports autolinking (RN 0.60+ for core, RN 0.63+ for Windows).
affects: <0.60 (core RN), <0.63 (Windows)
gotchaAfter installation and linking, Android projects require an additional manual step to apply a plugin in `android/app/build.gradle` for `react-native-config` to function correctly. Failure to do so will result in build errors or variables not being loaded.
fix
Add `apply from: project(':react-native-config').project` to the second line of your `android/app/build.gradle` file. Alternatively, use `npx react-native-integrate react-native-config`.
affects: >=1.0.0
gotchaWhen using `react-native-config` in an iOS project that utilizes Cocoapods, you must run `pod install` in the `ios/` directory after adding the package to your `package.json` to ensure the native module is correctly linked.
fix
Navigate to your `ios` directory (`cd ios`) and run `pod install`. Clean your build folder in Xcode afterwards (`Product > Clean Build Folder`).
affects: >=1.0.0
gotchaProjects upgrading to or using React Native's New Architecture (Fabric, TurboModules) on iOS or Android may encounter build issues if `react-native-config` isn't properly configured or if an incompatible version is used. Version 1.6.0+ introduced specific support for the new architecture.
fix
Ensure you are on `react-native-config@1.6.0` or higher for New Architecture support. Follow the specific New Architecture setup steps provided in the official documentation, which often involves codegen and proper project configuration.
affects: ~1.0.0 - 1.5.x (with New Arch); >1.6.0 (improper setup)
Errors
Common errors & fixes
error: cannot find symbol class RNCConfigPackage
The `react-native-config` package's Android native module is not correctly linked or `MainApplication.java` is missing package registration.
fix
Verify manual linking steps for Android (`settings.gradle`, `app/build.gradle`, `MainApplication.java`) and ensure `apply from: project(':react-native-config').project` is in `android/app/build.gradle`. If using autolinking, ensure caches are cleared and rebuild (`./gradlew clean`).
Invariant Violation: `Config` has not been registered. This can happen if the `Config` module wasn't linked correctly.
The native module for `react-native-config` failed to load for iOS or Android, meaning the JavaScript bridge cannot find the `Config` object.
fix
For iOS, run `cd ios && pod install` and clean the build folder (`Product > Clean Build Folder`) in Xcode. For Android, ensure all manual linking steps are followed, especially the `apply from` line in `app/build.gradle`, and then clean the Gradle cache (`./gradlew clean`). For older RN versions, ensure manual linking is complete as per documentation.
Undefined symbol: _OBJC_CLASS_$_RNCConfig
The `ReactNativeConfig.xcodeproj` or `libRNCConfig.a` is not correctly linked in Xcode, or `pod install` was not run after adding the package.
fix
If using Cocoapods, navigate to `ios` and run `pod install`. If not using Cocoapods or for manual linking, ensure `ReactNativeConfig.xcodeproj` is added to `Libraries` and `libRNCConfig.a` is in `Build Phases` -> `Link Binary With Libraries` in your Xcode project. Clean Xcode build folder and derived data.
Property 'API_URL' does not exist on type 'Readonly<{}>'.
TypeScript is not aware of the specific environment variables defined in your `.env` file, defaulting `Config` to an empty object type.
fix
Create a declaration file (e.g., `src/types/env.d.ts` or `env.d.ts`) in your project root and declare the module with your environment variables. Example: `declare module 'react-native-config' { export interface NativeConfig { API_URL: string; GOOGLE_MAPS_API_KEY: string; [key: string]: string | undefined; } export const Config: NativeConfig; export default Config; }`
A problem occurred evaluating project ':app'. > Project with path ':react-native-config' could not be found.
The `include ':react-native-config'` line or the `project(':react-native-config').projectDir` mapping in `android/settings.gradle` is incorrect or missing, preventing Gradle from locating the native module.
fix
Verify the `android/settings.gradle` file contains both `include ':react-native-config'` and the correct `project(':react-native-config').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-config/android')`.
Upgrade
Version history
1.6.1latest on npm
Audit
Dependencies
reactrequiredPeer dependency for React Native environment.
react-nativerequiredCore dependency for React Native application environment.
react-native-windowsoptionalPeer dependency for Windows platform support.
Agent activity
4 hits · last 30 days
node
4
Resources