{"id":19139,"library":"babel-plugin-react-require","title":"babel-plugin-react-require","description":"A Babel plugin (v4.0.3) that automatically adds an ES2015 import for React to files containing JSX tags. It targets stateless functional components that do not explicitly import React, saving boilerplate. Works with Babel 7+ (v4) and Babel 6 (v3). Released less frequently, with no updates in several years; similar functionality is now partially covered by @babel/preset-react with the 'runtime: automatic' option.","status":"maintenance","version":"4.0.3","language":"javascript","source_language":"en","source_url":"https://github.com/vslinko/babel-plugin-react-require","tags":["javascript","babel","babel-plugin","react","jsx"],"install":[{"cmd":"npm install babel-plugin-react-require","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-react-require","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-react-require","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required as a peer dependency for Babel plugin compatibility.","package":"@babel/core","optional":false}],"imports":[{"wrong":"// Not applicable; plugin is used via Babel config, not imported in code.","symbol":"default export of plugin","correct":"// in .babelrc: { \"plugins\": [\"react-require\"] }"}],"quickstart":{"code":"// .babelrc\n{\n  \"plugins\": [\"react-require\"]\n}\n\n// component.js (no explicit React import)\nexport default function Component() {\n  return <div />;\n}\n\n// After transpilation, React is imported automatically:\n// import React from 'react';","lang":"javascript","description":"Configures Babel to auto-import React in files with JSX."},"warnings":[{"fix":"Use @babel/preset-react with { \"runtime\": \"automatic\" } instead.","message":"With @babel/preset-react's automatic runtime (React 17+), React does not need to be in scope for JSX, making this plugin unnecessary for new projects.","severity":"deprecated","affected_versions":">=4.0"},{"fix":"Order plugins: [\"react-require\", \"transform-es2015-modules-commonjs\"]","message":"Plugin must be placed before transform-es2015-modules-commonjs in Babel 6 to ensure ES import syntax is used.","severity":"gotcha","affected_versions":">=3.0 <4.0"},{"fix":"Manually import named exports: import { useState } from 'react';","message":"Only adds the import for files containing JSX. If you use React API like useState, useEffect, or createContext, you still need to import them explicitly.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"npm install babel-plugin-react-require --save-dev","cause":"Plugin not installed as a devDependency.","error":"Error: Cannot find module 'babel-plugin-react-require'"},{"fix":"Add @babel/preset-react to your Babel config: { \"presets\": [\"@babel/preset-react\"] }","cause":"Missing JSX preset/plugin; this plugin only adds the import, not JSX transformation.","error":"SyntaxError: ... Support for the experimental syntax 'jsx' isn't currently enabled"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}