Registry / devops / babel-plugin-define-var

babel-plugin-define-var

JSON →
library0.1.0jsnpmunverified

A Babel plugin (v0.1.0) that adds missing variable declarations in the root scope after wyw-in-js pre-evaluation removes some identifiers, fixing '_c is not defined' errors. Useful for projects using MUI system, emotion, or styled-components with React Refresh (Next.js, Vite). The plugin is minimal and specific—there are no alternatives with the same narrow fix. Release cadence is low; this is the only version. No breaking changes expected due to simple scope.

npm install babel-plugin-define-var
INSTALL
IMPORT
SIG · BABEL-PLUGIN-DEFIN
B
babel-plugin-define-var
devopsjavascriptv0.1.0
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
import plugin from 'babel-plugin-define-var'
const plugin = require('babel-plugin-define-var')
ESM only; no named export.
plugin
// .babelrc { "plugins": ["babel-plugin-define-var"] }
Configure via string in Babel config, not imported directly.
plugin
const plugin = require('babel-plugin-define-var').default
const plugin = require('babel-plugin-define-var')
In CommonJS, must use .default because plugin is a default export.

Configures Babel plugin to fix missing variable declarations after wyw-in-js pre-evaluation with React Refresh.

// Install first: npm install babel-plugin-define-var // .babelrc { "plugins": ["babel-plugin-define-var"] } // Or in babel.config.js: module.exports = { plugins: ['babel-plugin-define-var'], }; // The plugin will automatically add missing var declarations like '_c = ...'
Debug
Known issues
gotchaPlugin only targets root scope; if missing declarations are nested, it won't fix them.
fix
Check plugin source or file an issue if nested vars are missing.
affects: >=0.1.0
gotchaOnly works when wyw-in-js is used; plugin does nothing otherwise.
fix
Ensure wyw-in-js is in your Babel chain and produces the missing var problem.
affects: >=0.1.0
Errors
Common errors & fixes
_c is not defined
wyw-in-js pre-evaluation removes variable declaration for '_c' when paired with React Refresh.
fix
Add babel-plugin-define-var to your Babel plugins.
_c1 is not defined
Same as above but for second variable.
fix
Add babel-plugin-define-var to your Babel plugins.
$RefreshReg$ is not defined
React Refresh global not available during wyw-in-js evaluation; plugin does not fix this.
fix
Ensure React Refresh is properly set up (e.g., in Next.js or Vite) and wyw-in-js config removes it.
Upgrade
Version history
0.1.0latest on npm
Audit
Dependencies
@babel/corerequiredBabel plugin API dependency, used at runtime
Agent activity
4 hits · last 30 days
node
4
Resources
babel-plugin-define-var — npm install babel-plugin-define-var · libregistry