pre-commit language: node Environments
language: node makes pre-commit build a Node environment for the hook, installing the package and any dependencies.
Node hooks like prettier and eslint run in their own pre-commit-managed Node environment, isolated from your project node_modules.
What it does
For a language: node hook, pre-commit provisions a Node environment (downloading the requested Node version if it is not present), installs the hook package and additional_dependencies, and runs entry. The environment is cached like every other hook env.
Common usage
- repo: https://github.com/pre-commit/mirrors-prettier
rev: v3.1.0
hooks:
- id: prettier
additional_dependencies:
- prettier@3.3.0
- prettier-plugin-svelte@3.2.0Keys
| Key | What it does |
|---|---|
| language: node | Build a Node environment for the hook |
| language_version | Node version, e.g. 20.11.1 |
| additional_dependencies | Extra npm packages (pin with name@version) |
| entry | Command run in the Node env |
| default | Use the system Node instead of downloading one |
In CI
If language_version names a Node version, pre-commit downloads it via its node provisioner, which needs network access; behind a proxy or on an offline runner this fails. Setting language_version: default uses the runner Node from setup-node instead. Cache ~/.cache/pre-commit so the Node env and node_modules are reused.
Common errors in CI
A hang or failure on "[INFO] Installing environment for ... node" often means the Node download is blocked; use language_version: default with a pre-installed Node. "npm ERR! ... ETIMEDOUT" during env build is the npm install failing on a restricted network. A mismatched plugin version in additional_dependencies surfaces as a prettier or eslint plugin-not-found error.