ESLint Environment for React Native Globals
eslint-plugin-react-native-globals is a lightweight ESLint plugin designed to provide an environment that acknowledges common React Native global variables and APIs. Its primary purpose is to prevent `no-undef` errors for built-in React Native globals (like `__DEV__`, `__dirname`, `__filename`, `process`, `global`, `console`, `setTimeout`, `setInterval`, etc.) without needing to disable the `no-undef` rule entirely. This allows developers to maintain strict linting for undefined variables while working with the React Native specific global scope. The package is currently at version `0.1.2`, with its last significant update occurring in 2019. Due to its age and lack of recent updates, it can be considered abandoned or in indefinite maintenance mode, with no predictable release cadence. Newer React Native versions might introduce globals not covered by this plugin.
Common errors
-
Error: Failed to load plugin 'react-native-globals' declared in '.eslintrc.json': Cannot find module 'eslint-plugin-react-native-globals'
cause The `eslint-plugin-react-native-globals` package was not installed or is not accessible in the current environment.fixRun `npm install --save-dev eslint-plugin-react-native-globals` or `yarn add --dev eslint-plugin-react-native-globals` in your project's root directory. If ESLint is installed globally, install the plugin globally too. -
Error: The 'env' key 'react-native-globals/all' is unknown.
cause The `react-native-globals` plugin is not correctly listed in the `plugins` array of your `.eslintrc` configuration, or there's a typo in the `env` key.fixEnsure your `.eslintrc` file contains `"plugins": ["react-native-globals"]` and `"env": {"react-native-globals/all": true}` as shown in the quickstart, with correct casing and spelling.
Warnings
- breaking The package `eslint-plugin-react-native-globals` is abandoned, with its last commit in April 2019 and version 0.1.2. It may not support newer React Native globals or be compatible with recent major versions of ESLint (e.g., ESLint v9+ which uses a new configuration format).
- gotcha If you install ESLint globally (which is generally discouraged), you must also install `eslint-plugin-react-native-globals` globally for ESLint to locate it correctly.
- gotcha This plugin only provides global variable definitions. It does not include any specific linting rules for React Native code styles or best practices. For rules, you need `eslint-plugin-react-native` or similar.
Install
-
npm install eslint-plugin-react-native-globals -
yarn add eslint-plugin-react-native-globals -
pnpm add eslint-plugin-react-native-globals
Imports
- ESLint Configuration
{ "plugins": ["react-native-globals"], "env": {"react-native-globals/all": true} }
Quickstart
{
"plugins": [
"react-native-globals"
],
"env": {
"react-native-globals/all": true
},
"rules": {
// Example: Ensure no-undef is still active for non-React Native globals
"no-undef": "error"
}
}