RequireJS Babel plugin

raw JSON →
0.0.9 verified Sat Apr 25 auth: no javascript abandoned

An AMD loader plugin for RequireJS that transpiles ES6/ES2015 modules via Babel at build or runtime. Currently at version 0.0.9, this package bundles an outdated Babel 5.8.22 and has been unmaintained since 2015. It is superseded by native ES6 support in modern browsers and tools like Webpack/Rollup with Babel presets. Key differentiator: easy integration with legacy RequireJS projects needing ES6 module loading.

error Error: Load timeout for modules: es6!app
cause The 'es6' path in requirejs.config is incorrect or the plugin file is missing.
fix
Ensure paths.es6 points to the directory containing es6.js, and paths.babel points to the babel bundle.
error Uncaught Error: Module name 'babel' has not been loaded yet for context: _
cause The 'babel' dependency path is misconfigured or the bundle is missing.
fix
Check that paths.babel points to the correct babel-5.8.22.min.js file (without .js extension in config).
error define is not defined
cause RequireJS is not loaded before calling define.
fix
Add <script src='require.js' data-main='main'></script> to HTML before any define calls.
deprecated RequireJS Babel is unmaintained. Babel 5 is outdated and incompatible with modern Babel versions (6+).
fix Migrate to a modern bundler like Webpack or Rollup with @babel/preset-env.
gotcha The plugin includes Babel as a single-file minified bundle (babel-5.8.22.min). This is a very old version with limited ES2015 support.
fix If you must use RequireJS, consider using a newer transpiler like TypeScript or a different plugin.
gotcha All modules loaded with 'es6!' are transpiled at runtime, which can slow down initial page load significantly.
fix Use the RequireJS optimizer (r.js) to pre-transpile modules in production.
breaking Babel 5 uses 'blacklist' and 'whitelist' options instead of 'presets'. Configuring via modern Babel options will not work.
fix Set options via requirejs.babel config object with Babel 5 API: { blacklist: ['regenerator'], optional: ['asyncToGenerator'] }.
npm install requirejs-babel
yarn add requirejs-babel
pnpm add requirejs-babel

Shows how to configure RequireJS with the babel plugin and load an ES6 module using the 'es6!' prefix.

// index.html
<script data-main="main" src="require.js"></script>
// main.js
requirejs.config({
  paths: {
    es6: 'bower_components/requirejs-babel/es6',
    babel: 'bower_components/requirejs-babel/babel-5.8.22.min'
  }
});
require(['es6!app'], function(app) { app.run(); });
// app.js (ES6)
define(function() {
  'use strict';
  return { run: () => console.log('ES6 works!') };
});