metro-eslint

raw JSON →
0.0.5 verified Sat Apr 25 auth: no javascript

Metro is the JavaScript bundler for React Native, providing fast reload cycles, scalable module bundling, and deep integration with React Native projects. This package, metro-eslint, is an ESLint plugin for Metro. Current stable version is 0.84.3 (released regularly, with breaking changes only in major versions). Key differentiators: sub-second HMR, built-in support for React Native's platform-specific extensions, and advanced caching. Alternatives: Webpack with React Native web support, but Metro is the default and recommended bundler for React Native. This specific package provides ESLint rules tailored to Metro's resolution and configuration.

error Error: Cannot find module 'metro-eslint'
cause Missing dependency; metro-eslint is not installed.
fix
npm install --save-dev metro-eslint
error Parsing error: The keyword 'import' is reserved
cause ESLint is not configured to parse ESM syntax; metro-eslint requires ESM.
fix
Add 'parserOptions: { sourceType: 'module' }' to .eslintrc or use .mjs extension.
error Error: 'metro' plugin is not defined
cause The metro-eslint plugin is not registered in ESLint config.
fix
Add 'plugins: ["metro"]' to your ESLint config.
breaking Dropped support for Node.js v21, v23, and LTS minors released before v20.19 in v0.84.0.
fix Upgrade Node.js to v20.19 or later, or v22.
deprecated The require('metro-config') pattern is deprecated in favor of ESM imports as of v0.83.0.
fix Use import { mergeConfig } from 'metro-config' instead.
gotcha Config files must use .cjs extension when using CommonJS; .mjs or .js are treated as ESM.
fix Use module.exports in .cjs files, or export default in .mjs/.js files.
breaking Metro v0.83.0 introduced ESM-only config support, breaking CommonJS require('metro-config').
fix Switch to import { mergeConfig } from 'metro-config' in .mjs or .js config files.
npm install metro-eslint
yarn add metro-eslint
pnpm add metro-eslint

Minimal setup for using metro-eslint plugin in an ESLint configuration file.

// Add to .eslintrc.cjs
module.exports = {
  plugins: ['metro'],
  extends: ['plugin:metro/recommended'],
  rules: {
    'metro/no-env-with-spread': 'error',
  },
};