Registry / devops / grunt-babel

grunt-babel

JSON →
library8.0.0jsnpmunverified

grunt-babel is a Grunt plugin that integrates Babel, allowing developers to transpile modern JavaScript code (ESNext) into backward-compatible versions for older environments using the Grunt task runner. The current stable version is v8.0.0, which is specifically designed for compatibility with Babel 7.x. While Grunt itself has a slower release cadence compared to modern build tools, `grunt-babel` follows Babel's major version releases closely, necessitating updates to maintain compatibility. Its primary differentiator is its deep integration into the Grunt ecosystem, providing a familiar configuration experience for projects already utilizing Grunt for their build processes. It leverages Babel's extensive plugin and preset system, enabling a wide range of transformations, from JSX and TypeScript syntax stripping to polyfilling modern JavaScript features, making it suitable for projects that prefer a Grunt-centric workflow over newer alternatives like Webpack or Rollup.

npm install grunt-babel
INSTALL
IMPORT
SIG · GRUNT-BABEL
G
grunt-babel
devopsjavascriptv8.0.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.

babel
grunt.initConfig({ babel: { /* ... */ } });
import { babel } from 'grunt-babel';
grunt-babel is a Grunt task, not a library for direct import. Its functionality is configured via `grunt.initConfig`.
options
grunt.initConfig({ babel: { options: { sourceMap: true, presets: ['@babel/preset-env'] }, // ... } });
const babelOptions = require('grunt-babel').options;
Configuration options are passed directly within the Grunt task definition object, not imported.
default task registration
grunt.registerTask('default', ['babel']);
grunt.registerTask('babel', ['default']);
This registers a Grunt task named 'default' that runs the 'babel' task. The `babel` task itself is implicitly registered by the plugin.

This quickstart configures grunt-babel to transpile 'src/app.js' into 'dist/app.js' using source maps and the '@babel/preset-env' preset, then registers it as the default Grunt task.

require('load-grunt-tasks')(grunt); // npm install --save-dev load-grunt-tasks grunt.initConfig({ babel: { options: { sourceMap: true, presets: ['@babel/preset-env'] // Ensure @babel/preset-env is installed }, dist: { files: { 'dist/app.js': 'src/app.js' } } } }); grunt.registerTask('default', ['babel']);
Debug
Known issues
breakinggrunt-babel v8 requires Babel 7.x. Upgrading from v7 (Babel 6.x) requires updating all Babel related packages (e.g., `babel-core` to `@babel/core`, `babel-preset-env` to `@babel/preset-env`).
fix
Ensure all Babel packages are updated to their `@babel/` scoped versions (e.g., `npm install --save-dev @babel/core @babel/preset-env`) and configuration paths are adjusted accordingly.
affects: >=8.0.0
breakingNode.js v4 support was dropped in grunt-babel v8. Projects using older Node.js versions must remain on grunt-babel v7.
fix
Upgrade Node.js to a supported version (>=6.9 for grunt-babel v8), or explicitly install `grunt-babel@7` for Babel 6.x compatibility and Node.js v4-v5 support.
affects: >=8.0.0
breakingThe `babel-core` package became a peerDependency in v7.0.0. Failure to install it will lead to runtime errors as `grunt-babel` cannot find the core transpiler.
fix
Manually install `@babel/core` (for v8+) or `babel-core` (for v7) in your project: `npm install --save-dev @babel/core`.
affects: >=7.0.0
gotchaIssues with transpilation output (e.g., incorrect syntax, missing polyfills) are generally problems with Babel itself, not `grunt-babel`. These should be reported to the Babel issue tracker.
fix
Verify your Babel configuration (presets, plugins) and report core transpilation issues on the official Babel GitHub repository.
affects: >=6.0.0
Errors
Common errors & fixes
Error: Cannot find module '@babel/core'
The `@babel/core` peer dependency is not installed.
fix
Run `npm install --save-dev @babel/core` or `yarn add --dev @babel/core`.
Error: You have not specified any presets or plugins for babel.
Babel requires at least one preset or plugin to perform transformations. The options are empty or misconfigured.
fix
Add a preset like `@babel/preset-env` to your `babel.options.presets` array: `presets: ['@babel/preset-env']`. Ensure the preset package is also installed.
SyntaxError: 'import' and 'export' may only appear at the top level (when running outputted JS)
The transpiled output still contains ES module syntax but is being run in an environment that expects CommonJS, likely because a preset like `@babel/preset-env` was configured not to transform modules.
fix
Ensure `@babel/preset-env` is configured to transform modules, e.g., `presets: [['@babel/preset-env', { modules: 'commonjs' }]]`.
Upgrade
Version history
8.0.0latest on npm
Audit
Dependencies
gruntrequiredCore task runner dependency for any Grunt plugin.
@babel/corerequiredThe core Babel library responsible for transpilation; grunt-babel orchestrates its usage.
@babel/preset-envoptionalA common Babel preset to automatically determine necessary Babel plugins and polyfills based on target environments.
load-grunt-tasksoptionalA common utility for loading Grunt tasks from package.json, simplifying Gruntfile setup.
Agent activity
4 hits · last 30 days
node
4
Resources
grunt-babel — npm install grunt-babel · libregistry