Registry / devops / craco-babel-loader

craco-babel-loader

JSON →
library1.0.4jsnpmunverified

A CRACO plugin that allows you to rewire the babel-loader in your un-ejected create-react-app project to include or exclude custom paths (e.g., from node_modules) for transpilation. Version 1.0.4 is the latest stable release, supporting both @craco/craco v6 and v7. It fills a gap for CRA v2+ by enabling babel transpilation of external packages, which is especially useful for monorepos or when using ES6+ libraries from npm. Compared to alternatives like react-app-rewired, this plugin integrates directly with CRACO's configuration system and provides a simpler include/exclude API.

npm install craco-babel-loader
INSTALL
IMPORT
SIG · CRACO-BABEL-LOADER
C
craco-babel-loader
devopsjavascriptv1.0.4
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.

rewireBabelLoader
const rewireBabelLoader = require('craco-babel-loader');
import rewireBabelLoader from 'craco-babel-loader';
CommonJS require is the standard pattern for CRACO config files, which are usually executed in Node.js without ESM support.
rewireBabelLoader
import rewireBabelLoader from 'craco-babel-loader';
const rewireBabelLoader = require('craco-babel-loader').default;
Although CRACO configs typically use CommonJS, this package also exports an ESM default. Using .default is incorrect because the export is a direct function, not wrapped in a module object.
rewireBabelLoader
const rewireBabelLoader = require('craco-babel-loader');
const { rewireBabelLoader } = require('craco-babel-loader');
The package exports a single function as default, not a named export. Destructuring will result in undefined.

Shows how to add craco-babel-loader as a plugin in a CRACO config file, specifying which node_modules directories to include or exclude from babel transpilation.

// craco.config.js const path = require('path'); const fs = require('fs'); const rewireBabelLoader = require('craco-babel-loader'); const appDirectory = fs.realpathSync(process.cwd()); const resolveApp = relativePath => path.resolve(appDirectory, relativePath); module.exports = { plugins: [ { plugin: rewireBabelLoader, options: { includes: [resolveApp('node_modules/my-es6-package')], // optional excludes; defaults to /node_modules/ excludes: [/node_modules\/other-package/] } } ] };
Debug
Known issues
breakingRequires @craco/craco v6.4.2 or v7.0.0; older versions are incompatible.
fix
Ensure @craco/craco is at least version 6.4.2 or 7.0.0.
affects: <1.0.4
gotchaThe plugin only works with un-ejected create-react-app projects using CRACO. It does not work with react-app-rewired or ejected CRA.
fix
Use only with CRA + CRACO; for react-app-rewired, use react-app-rewire-babel-loader.
affects: >=0.0.0
gotchaOptions includes and excludes are arrays of paths or regexes; single values must be wrapped in an array.
fix
Always provide an array for includes/excludes: includes: ['/path'].
affects: >=0.0.0
deprecatedThe package uses deprecated babel-loader APIs internally; may break with future babel-loader versions.
fix
Monitor babel-loader updates; consider switching to @craco/craco's built-in babel configuration if possible.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'craco-babel-loader'
Package not installed or missing from node_modules.
fix
Run 'npm install craco-babel-loader' or 'yarn add craco-babel-loader'.
TypeError: plugin is not a function
Incorrect import or destructuring; craco-babel-loader exports a function as default, not a named export.
fix
Use 'const rewireBabelLoader = require("craco-babel-loader");' and pass it as { plugin: rewireBabelLoader }.
Error: Invalid plugin options: includes must be an array
Passed a single path/string instead of an array for includes or excludes option.
fix
Wrap the path in an array: includes: [resolveApp('path/to/include')].
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies
@craco/cracorequiredThis plugin is designed to be used as a CRACO plugin; @craco/craco is a peer dependency required at runtime for the configuration to work.
Agent activity
12 hits · last 30 days
node
10
Resources
craco-babel-loader — npm install craco-babel-loader · libregistry