{"id":11121,"library":"jake","title":"Jake","description":"Jake is a JavaScript build tool and task runner for Node.js, designed to operate similarly to traditional build systems like GNU Make or Ruby's Rake. It is currently at version 12.9.7, with active maintenance and a consistent release cadence to support newer Node.js versions. Key differentiators include defining build tasks in plain JavaScript files (Jakefiles), supporting complex task prerequisites, namespacing for organization, and handling asynchronous task execution. Jake offers synchronous file utilities for common build operations and can be installed globally as a CLI, locally as a dev dependency, or embedded programmatically within other applications. It has a long history in the Node.js ecosystem, indicating a mature and well-tested codebase.","status":"active","version":"12.9.7","language":"javascript","source_language":"en","source_url":"git://github.com/jakejs/jake","tags":["javascript","build","cli","make","rake"],"install":[{"cmd":"npm install jake","lang":"bash","label":"npm"},{"cmd":"yarn add jake","lang":"bash","label":"yarn"},{"cmd":"pnpm add jake","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Jakefiles are typically executed in a CommonJS context. While `desc`, `task`, and `namespace` functions are often available implicitly as globals within a Jakefile, explicit `require` is the recommended and clearest approach, especially for programmatic use or when using other API methods. ESM `import` is not natively supported for Jakefiles and may lead to errors without transpilation.","wrong":"import { desc, task, namespace } from 'jake';","symbol":"desc, task, namespace","correct":"const { desc, task, namespace } = require('jake');"},{"note":"The `jake` object, containing utility methods like `exec` for running shell commands, `mkdirP`, `cpR`, etc., is accessed via `require('jake')` in a CommonJS context. Ensure to handle asynchronous `jake.exec` calls with a callback.","wrong":"import jake from 'jake'; jake.exec(...);","symbol":"jake.exec","correct":"const jake = require('jake');\njake.exec(['command'], { printStdout: true }, () => {\n  console.log('Command finished.');\n});"},{"note":"To programmatically invoke a defined task (including its prerequisites), access it via `Task['namespace:taskName']`. The `Task` object is available from `require('jake')`.","wrong":"const jake = require('jake'); jake.Task.invoke('my:task');","symbol":"Task['my:task'].invoke()","correct":"const { Task } = require('jake');\nTask['my:task'].invoke();"}],"quickstart":{"code":"/* Jakefile.js */\nconst { desc, task, namespace } = require('jake');\n\ndesc('This is the default task.');\ntask('default', function () {\n  console.log('Running the default task.');\n});\n\nnamespace('build', function () {\n  desc('Cleans the build directory.');\n  task('clean', function () {\n    console.log('Cleaning build artifacts...');\n    // Example: jake.rmRf('dist'); (requires 'jake' object)\n  });\n\n  desc('Compiles source files.');\n  task('compile', ['build:clean'], function () {\n    console.log('Compiling source...');\n    // Simulate async operation\n    setTimeout(() => {\n      console.log('Compilation complete.');\n      this.complete(); // Important for async tasks\n    }, 1000);\n  }, { async: true });\n\n  desc('Lints JavaScript files.');\n  task('lint', function () {\n    console.log('Running linter...');\n  });\n\n  desc('Performs a full build, including linting.');\n  task('all', ['build:lint', 'build:compile'], function () {\n    console.log('Full build finished!');\n  });\n});\n\ndesc('Runs all tests.');\ntask('test', ['build:all'], function () {\n  console.log('Running tests...');\n});\n\n// To run:\n// npm install -g jake\n// jake default\n// jake build:all\n// jake test","lang":"javascript","description":"This quickstart demonstrates how to define tasks and namespaces in a `Jakefile.js`, including prerequisites and an asynchronous task, and how to execute them from the command line."},"warnings":[{"fix":"Always use CommonJS `require()` syntax for modules within your `Jakefile.js`. For core Jake API, prefer destructuring `require('jake')` or relying on globals if implicitly available in your specific Jake setup.","message":"Jakefiles are executed in a CommonJS context. Attempting to use ES Modules `import` syntax directly in a `Jakefile.js` will likely result in a `SyntaxError: Cannot use import statement outside a module` or similar, as Jake does not natively support ESM for task definition files.","severity":"gotcha","affected_versions":">=0.1"},{"fix":"Update your Node.js runtime to version 10 or newer. Refer to Jake's `package.json` for the exact minimum Node.js requirement.","message":"Jake drops support for older Node.js versions with major releases. Users should always check the `engines.node` field in `package.json` to ensure compatibility with their Node.js environment. Currently, Node.js `>=10` is required.","severity":"breaking","affected_versions":">=10.0.0"},{"fix":"For any task involving asynchronous operations (e.g., `setTimeout`, `jake.exec` with callbacks, Promises), define it as `task('myTask', { async: true }, function () { /* ... async work ... */ this.complete(); });`.","message":"When defining asynchronous tasks, the task function *must* be marked with `{ async: true }` in its options object and *must* explicitly call `this.complete()` when the asynchronous work is finished. Failure to do so will result in Jake completing the task immediately, potentially before work is done, or hanging indefinitely.","severity":"gotcha","affected_versions":">=0.1"},{"fix":"Consider installing Jake locally as a development dependency (`npm install --save-dev jake`) and invoking it using `npx jake [task]` from your project's root. If installing globally, ensure your system's PATH variable is correctly configured.","message":"On Windows, global installation of Jake (e.g., `npm install -g jake`) has historically led to issues where the `jake` command is not recognized or behaves unexpectedly, potentially trying to run shell scripts. While some issues may be resolved, local installation (`npm install jake`) and execution via `npx jake` is often more robust.","severity":"gotcha","affected_versions":">=0.1"},{"fix":"Use `Task['my:task'].reenable()` before calling `Task['my:task'].invoke()` if the task needs to execute more than once within a single Jake run.","message":"When programmatically invoking tasks, `Task['my:task'].invoke()` will execute the task and its prerequisites only once, even if called multiple times within a build. If a task needs to be run multiple times, it must be 'reenabled' using `Task['my:task'].reenable()` before each subsequent invocation.","severity":"gotcha","affected_versions":">=0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install Jake globally (`npm install -g jake`) and ensure npm's global bin directory is in your system PATH, or install it locally (`npm install --save-dev jake`) and run tasks using `npx jake [taskName]`.","cause":"Jake is not installed globally or its installation directory is not in the system's PATH, or a local installation is not being invoked via `npx`.","error":"'jake' is not recognized as an internal or external command, operable program or batch file."},{"fix":"Refactor the `Jakefile.js` and any directly loaded modules to use CommonJS `require()` syntax instead of ESM `import`. Jakefiles inherently run in a CJS context.","cause":"An `import` statement was used in a `Jakefile.js` or a module loaded by it, which Node.js is treating as a CommonJS module.","error":"SyntaxError: Cannot use import statement outside a module"},{"fix":"Verify the task name spelling, ensure the `Jakefile.js` is in the current directory or specified with `-f`, and check the `Jakefile.js` for JavaScript syntax errors. Use `jake -T` to list available tasks.","cause":"The specified task name does not match any task defined in the `Jakefile.js`, or the `Jakefile.js` itself was not found or has syntax errors preventing task definition.","error":"Task not found: my-nonexistent-task"},{"fix":"Ensure all asynchronous tasks explicitly call `this.complete()` after their operations have finished to signal completion to Jake.","cause":"An asynchronous task was defined (with `{ async: true }`) but did not call `this.complete()` at the end of its execution, causing Jake to detect an incomplete task.","error":"Error: asynchronous task function completed without calling 'complete()'"}],"ecosystem":"npm"}