{"id":10983,"library":"grunt","title":"Grunt: The JavaScript Task Runner","description":"Grunt is a JavaScript task runner designed to automate repetitive development tasks such as minification, compilation, linting, and testing. It operates primarily through a command-line interface (CLI) and is configured declaratively via a `Gruntfile.js` located in a project's root. The current stable version is 1.6.2, requiring Node.js >=16. Grunt's release cadence is opportunistic, focusing on dependency updates, bug fixes, and maintaining compatibility with modern Node.js environments. Its key differentiators include a mature, stable architecture, a configuration-over-code paradigm that allows developers to define tasks and settings in a structured format, and a rich ecosystem of community-contributed plugins for diverse build processes. This declarative approach, contrasted with more programmatic build tools, makes Grunt accessible for automating complex workflows.","status":"active","version":"1.6.2","language":"javascript","source_language":"en","source_url":"https://github.com/gruntjs/grunt","tags":["javascript","task","async","cli","minify","uglify","build","lodash","unit"],"install":[{"cmd":"npm install grunt","lang":"bash","label":"npm"},{"cmd":"yarn add grunt","lang":"bash","label":"yarn"},{"cmd":"pnpm add grunt","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required globally or locally to run Grunt tasks from the command line. It acts as the entry point that finds and executes the locally installed `grunt` package.","package":"grunt-cli","optional":false}],"imports":[{"note":"The core 'grunt' package is not typically imported directly into user application code. Instead, the 'grunt' object, which contains all the API methods, is passed as an argument to the function exported by your Gruntfile.js. Gruntfiles are generally CommonJS modules.","wrong":"import { initConfig } from 'grunt';\nconst grunt = require('grunt');","symbol":"grunt object in Gruntfile.js","correct":"module.exports = function(grunt) { /* ... */ };"},{"note":"Used within a Gruntfile.js to define project and task-specific configuration. It's the primary way to configure tasks and access project metadata.","symbol":"grunt.initConfig","correct":"module.exports = function(grunt) {\n  grunt.initConfig({\n    pkg: grunt.file.readJSON('package.json'),\n    uglify: { /* ... */ }\n  });\n};"},{"note":"Loads tasks from installed Grunt plugins. This makes the tasks available for configuration and execution within your Gruntfile.js.","symbol":"grunt.loadNpmTasks","correct":"module.exports = function(grunt) {\n  // ...\n  grunt.loadNpmTasks('grunt-contrib-uglify');\n};"}],"quickstart":{"code":"{\n  \"name\": \"my-project\",\n  \"version\": \"0.1.0\",\n  \"devDependencies\": {\n    \"grunt\": \"^1.6.0\",\n    \"grunt-contrib-uglify\": \"^5.0.0\",\n    \"grunt-contrib-watch\": \"^1.1.0\"\n  }\n}\n\n// Gruntfile.js\nmodule.exports = function(grunt) {\n\n  grunt.initConfig({\n    pkg: grunt.file.readJSON('package.json'),\n    uglify: {\n      options: {\n        banner: '/*! <%= pkg.name %> <%= grunt.template.today(\"yyyy-mm-dd\") %> */\\n'\n      },\n      build: {\n        src: 'src/<%= pkg.name %>.js',\n        dest: 'dist/<%= pkg.name %>.min.js'\n      }\n    },\n    watch: {\n      scripts: {\n        files: ['src/**/*.js'],\n        tasks: ['uglify'],\n        options: {\n          spawn: false,\n        },\n      },\n    },\n  });\n\n  grunt.loadNpmTasks('grunt-contrib-uglify');\n  grunt.loadNpmTasks('grunt-contrib-watch');\n\n  grunt.registerTask('default', ['uglify']);\n  grunt.registerTask('dev', ['default', 'watch']);\n};","lang":"javascript","description":"This quickstart demonstrates a basic Grunt setup, including `package.json` for dependencies and a `Gruntfile.js` to define tasks for JavaScript minification and file watching. After `npm install`, running `grunt` executes the default `uglify` task, while `grunt dev` will minify and then watch for changes."},"warnings":[{"fix":"Ensure your `Gruntfile.js` uses CommonJS syntax (`module.exports = function(grunt) { ... };`). If you need to use ESM in custom tasks, you might need to transpile them or use dynamic `import()` within a CJS Gruntfile.","message":"Gruntfiles are traditionally CommonJS modules (using `module.exports`). Attempting to use ES Modules syntax (`import`/`export`) directly in your `Gruntfile.js` will likely result in a `ERR_REQUIRE_ESM` error. While Node.js supports ESM, Grunt itself does not natively support ESM Gruntfiles without transpilation or specific workarounds.","severity":"breaking","affected_versions":"All versions"},{"fix":"Regularly update to the latest stable minor version of Grunt (currently 1.6.x). If maintaining older projects, consider commercial support options like those offered by HeroDevs mentioned in the official documentation.","message":"Only the latest minor version of Grunt is actively supported for security and bug fixes. Older versions are considered end-of-life (EOL). Using EOL versions means you will not receive official updates for vulnerabilities or issues.","severity":"gotcha","affected_versions":"<1.6.0"},{"fix":"Review custom tasks and plugin implementations to ensure they are not making assumptions about underlying file system utility behavior that might have changed with internal dependency removal. Test thoroughly after upgrading.","message":"Grunt 1.6.1 removed internal dependencies on `rimraf` and `mkdirp`. While this primarily affects internal implementation, if any Grunt plugins or custom tasks were implicitly relying on `grunt.file` methods that previously delegated to these, there could be subtle behavioral changes.","severity":"breaking","affected_versions":">=1.6.1"},{"fix":"Ensure your development and build environments use Node.js version 16 or newer. Update Node.js if necessary.","message":"Grunt 1.6.0 bumped the minimum required Node.js version to `Node.js >=16`. Running Grunt on older Node.js environments will lead to errors.","severity":"breaking","affected_versions":">=1.6.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Rewrite `Gruntfile.js` and any directly loaded custom task files to use CommonJS syntax (`module.exports = function(grunt) { ... };` and `require()`). Ensure `package.json` does not have `\"type\": \"module\"` if Grunt is the primary runner.","cause":"Attempting to use ES module syntax (e.g., `import` or `export`) in `Gruntfile.js` or directly imported files, which Grunt does not natively support for its configuration files.","error":"Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: Gruntfile.js"},{"fix":"Install `grunt-cli` globally: `npm install -g grunt-cli`. Ensure your system's PATH includes npm global binaries. Alternatively, if installed locally, run `npx grunt` or add `./node_modules/.bin/grunt` to your PATH.","cause":"The `grunt-cli` package, which provides the `grunt` executable, is either not installed or not available in your system's PATH.","error":"grunt: command not found"},{"fix":"Verify that `grunt.registerTask('mytask', ...)` has been called, or if it's from a plugin, that `grunt.loadNpmTasks('grunt-contrib-mytask');` has been correctly used and the plugin is installed in `devDependencies`.","cause":"The specified task was not registered in the `Gruntfile.js`, or the plugin providing it was not loaded, or there's a typo in the task name.","error":"Warning: Task \"mytask\" not found. Use --force to continue."}],"ecosystem":"npm"}