Registry /
testing / canary-farm-lint-staged
Install & Compatibility
Where this runs
No compatibility data collected yet for this library.
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
lint-staged
✓ npx lint-staged --config .lintstagedrc.json
✗ const lintStaged = require('lint-staged')
lint-staged is typically used as a CLI tool, not a library import. Since v12, the package is ESM-only and requires Node >=14.13.1 or >=16. Using require() will fail with ERR_REQUIRE_ESM.
export default
✓ // No programmatic API; use CLI or define in package.json
"lint-staged": {
"*.js": "eslint --fix"
}
✗ import lintStaged from 'lint-staged'
There is no programmatic API; lint-staged is designed to be run as a CLI tool or via git hooks. Attempting to import the package directly will result in runtime errors.
Configuration
✓ // In .lintstagedrc.json:
{
"*.js": ["eslint --fix", "git add"]
}
✗ {
"*.js": "eslint --fix && git add"
}
Since v10, lint-staged automatically adds any modifications to the index, so the `git add` step should not be included in the task. Including it may cause duplicate additions or conflicts.
Complete setup of lint-staged with Husky, including installation, hook setup, and configuration example for ESLint and Prettier.
// 1. Install
npm install --save-dev lint-staged husky
// 2. Set up husky pre-commit hook
npx husky add .husky/pre-commit "npx lint-staged"
// 3. Add configuration to package.json:
"lint-staged": {
"*.js": "eslint --fix",
"*.{css,md}": "prettier --write"
}
// 4. Make a change and commit:
git add some-file.js
git commit -m "Add something"
// This will run eslint and prettier on the staged files before commit.
lint-staged --version
Debug
Known issues
breakingSince v12, lint-staged is ESM-only. Node versions <12.20.0, <14.13.1, or <16.0.0 are not supported.fixUpgrade Node.js to >=14.13.1 or >=16.0.0, and ensure your project uses ESM (i.e., type: module in package.json or .mjs extensions).
affects: >=12.0.0 <13.0.0
deprecatedThe `git add` command should not be included in tasks since v10. lint-staged automatically adds modifications from successful tasks to the index.fixRemove `git add` from task definitions. For example, change `"*.js": "eslint --fix && git add"` to `"*.js": "eslint --fix"`.
affects: >=10.0.0
gotchaIf a task fails, the original staged state is automatically restored. However, if staging fails (e.g., due to files being modified after the initial stash), the stash may not be restored correctly, leaving the working directory in an intermediate state.fixUse `--no-stash` to disable automatic stash if you do not want lint-staged to restore changes on failure, but be aware that modified files from successful tasks will remain.
affects: >=0.0.0
breakingNode.js 12 support dropped in v13.0.0. Version 12 is also ESM-only from v12.0.0.fixUpgrade Node.js to >=14.13.1 or >=16.0.0.
affects: >=13.0.0
gotchaWhen using `--concurrent` option, tasks are run in parallel. This can cause conflicts if tasks modify the same files.fixUse `--concurrent false` to run tasks sequentially, or design tasks to work on different file types.
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'lint-staged'
lint-staged is not installed or not in the PATH when running via npx/husky.
fixInstall as dev dependency: npm install --save-dev lint-staged
ERR_REQUIRE_ESM: require() of ES Module /path/to/lint-staged/index.js from /path/to/your-script.js not supported.
Using require() to import lint-staged in a CommonJS environment (Node <14 or without type:module).
fixUse npx lint-staged from command line or wrap it in an ES module (e.g., use .mjs extension or set type:module in package.json).
✖ lint-staged failed due to a git error:
error: Your local changes to the following files would be overwritten by checkout
The stash operation conflicts with uncommitted changes that are not staged.
fixCommit or stash all local changes before running lint-staged, or use --no-stash to disable automatic stashing.
No staged files found for the configured patterns.
The glob patterns in the configuration do not match any of the currently staged files.
fixCheck the list of staged files (git diff --name-only --cached) and adjust the patterns in lint-staged configuration to match them.
Upgrade
Version history
0.0.0-developmentlatest on npm
Audit
Dependencies
commanderrequiredCommand-line argument parsing
picomatchrequiredGlob pattern matching for file selection
tinyexecrequiredExternal process execution (replaced nano-spawn in v16.3.0)
huskyoptionalCommonly used to set up pre-commit hooks (optional but recommended peer dependency)