Babel Transform for bit-imports and bit-bundler

raw JSON →
1.0.1 verified Thu Apr 23 auth: no javascript abandoned

babel-bits is an npm package designed to integrate Babel 6 transformations within the bit-imports and bit-bundler ecosystems. It acts as a handler for JavaScript files, allowing them to be transpiled during the import or bundling process. The package, currently at its last stable version v1.0.1 released in 2017, wraps `babel-core` (v6) along with `babel-preset-es2015` and `babel-preset-react` as default configurations. The project and its parent `bit-imports` and `bit-bundler` dependencies appear to be abandoned, with no significant updates or maintenance since 2017. Key differentiators included its deep integration with the specific module loading and bundling mechanisms of `bit-imports` and `bit-bundler`, offering a pre-configured, albeit outdated, Babel setup for those systems. It does not follow a regular release cadence and is effectively end-of-life.

error Error: Cannot find module '@babel/core' or similar errors referencing new Babel packages.
cause babel-bits expects Babel 6 packages (e.g., `babel-core`), not Babel 7+ packages (e.g., `@babel/core`).
fix
Ensure babel-core, babel-preset-es2015, and babel-preset-react (all ^6.0.0) are installed as direct dependencies. Do NOT install @babel/core or other @babel/ scoped packages.
error ReferenceError: regeneratorRuntime is not defined
cause Babel 6 transforms generator functions (like `async/await`) into code that requires `regeneratorRuntime` to be available globally, but `babel-bits` does not automatically provide this polyfill.
fix
Install regenerator-runtime (npm install regenerator-runtime) and import it once at the top of your application's entry file: require('regenerator-runtime/runtime'); or ensure it's loaded via a script tag in the browser.
breaking babel-bits relies exclusively on Babel 6 (specifically `babel-core@^6.0.0`) and its associated presets. It is fundamentally incompatible with Babel 7+ due to significant API changes and package renames. Attempting to use it with a modern Babel setup will lead to errors.
fix Downgrade your Babel setup to Babel 6 if you must use babel-bits, or migrate away from babel-bits and the bit-imports/bit-bundler ecosystem to a modern bundler like Webpack or Rollup with Babel 7+.
deprecated The entire babel-bits, bit-imports, and bit-bundler ecosystem is considered abandoned. There have been no code updates or maintenance since 2017. Using this package in new projects is strongly discouraged, and existing projects should plan for migration.
fix Migrate your project to a currently maintained module bundler (e.g., Webpack, Rollup, Vite) and a modern Babel setup (Babel 7+).
gotcha When using Babel 6 (as babel-bits does) for generator functions (e.g., `async/await`), you must manually include `regeneratorRuntime` in your application's global scope. Babel 6 does not automatically polyfill this, leading to runtime errors.
fix Load the `regenerator-runtime` package (e.g., `require('regenerator-runtime/runtime')` or include via a script tag) at the entry point of your application before any transpiled generator code executes.
npm install babel-bits
yarn add babel-bits
pnpm add babel-bits

Demonstrates how to configure `babel-bits` as a transformation handler within `bit-imports`, enabling Babel 6 transpilation for loaded JavaScript files.

const bitimports = require('bit-imports');

// Configure bit-imports to use babel-bits for JavaScript transformations
bitimports.plugin('js', {
  transform: {
    handler: 'babel-bits', // Specify babel-bits as the transformation handler
    options: {
      sourceMaps: 'inline', // Enable inline source maps for debugging
      presets: ['es2015', 'react'] // Configure default Babel 6 presets
    }
  }
});

// Example of how bit-imports might then load a module
// In a real application, you would load your main application file here
// const myModule = bitimports.load('./src/main.js');
// console.log('bit-imports configured with babel-bits:', myModule);

console.log('babel-bits is configured via bit-imports plugin. No direct module interaction typically occurs.');
console.log('Ensure babel-core, babel-preset-es2015, and babel-preset-react are installed alongside.');