Registry / web-framework / babel-plugin-react-require

babel-plugin-react-require

JSON →
library4.0.3jsnpmunverified

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.

npm install babel-plugin-react-require
INSTALL
IMPORT
SIG · BABEL-PLUGIN-REACT
B
babel-plugin-react-require
web-frameworkjavascriptv4.0.3
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.

default export of plugin
// in .babelrc: { "plugins": ["react-require"] }
// Not applicable; plugin is used via Babel config, not imported in code.

Configures Babel to auto-import React in files with JSX.

// .babelrc { "plugins": ["react-require"] } // component.js (no explicit React import) export default function Component() { return <div />; } // After transpilation, React is imported automatically: // import React from 'react';
Debug
Known issues
deprecatedWith @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.
fix
Use @babel/preset-react with { "runtime": "automatic" } instead.
affects: >=4.0
gotchaPlugin must be placed before transform-es2015-modules-commonjs in Babel 6 to ensure ES import syntax is used.
fix
Order plugins: ["react-require", "transform-es2015-modules-commonjs"]
affects: >=3.0 <4.0
gotchaOnly adds the import for files containing JSX. If you use React API like useState, useEffect, or createContext, you still need to import them explicitly.
fix
Manually import named exports: import { useState } from 'react';
affects: *
Errors
Common errors & fixes
Error: Cannot find module 'babel-plugin-react-require'
Plugin not installed as a devDependency.
fix
npm install babel-plugin-react-require --save-dev
SyntaxError: ... Support for the experimental syntax 'jsx' isn't currently enabled
Missing JSX preset/plugin; this plugin only adds the import, not JSX transformation.
fix
Add @babel/preset-react to your Babel config: { "presets": ["@babel/preset-react"] }
Upgrade
Version history
4.0.3latest on npm
Audit
Dependencies
@babel/corerequiredRequired as a peer dependency for Babel plugin compatibility.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
babel-plugin-react-require — npm install babel-plugin-react-require · libregistry