← All tasks
javascriptlint-staged/lint-staged #1683Not a task: not reproduced

Fail to restore files after `SubprocessError` when run with `npx`

envgap__lint-staged__lint-staged-1683

01 / FAILURE SIGNATURE

As reported upstream

continueOnError: false,
Not a benchmark task.
  • In a clean container the reported failure did not reproduce, or the known fix did not make the project run.

02 / ENVIRONMENT RECIPE

Base commit
6ab937c4b0a151ffae28ad6c5faa3830136ffa4f
Manifest
package.json
Reproduce
Awaiting issue-specific recipe
Run under trace
Awaiting a meaningful runtime command

03 / ORIGINAL ISSUE TEXT

lint-staged/lint-staged #1683 · read the original issue
### Description

Running `lint-staged` through `npx` may result in all changes being stashed and not restored.
For that any check should fail with `ENOENT`.

Both conditions are easily met if forget to init `node_modules` and use `npx`.

### Steps to reproduce

1. Configuration should include any command that is **not installed**

package.json:
```json
    "lint-staged": {
        "*.{ts,tsx,js,jsx,vue}": [
            "unknown-command --fix'"
        ]
    },
```

2. `lint-staged` should be also missing in local `node_modules`;

3. Stage any matching file;
4. `npx lint-staged --debug -c ./package.json`;

### Debug Logs

<details>

<summary> expand to view </summary>

```
 npx lint-staged --debug -c ./package.json
lint-staged:bin: Using shell: /bin/bash +3ms
lint-staged:bin: Options parsed from command-line: {
  allowEmpty: false,
  concurrent: true,
  configPath: './package.json',
  continueOnError: false,
  cwd: undefined,
  debug: true,
  diff: undefined,
  diffFilter: undefined,
  failOnChanges: false,
  hidePartiallyStaged: true,
  hideUnstaged: false,
  maxArgLength: undefined,
  quiet: false,
  relative: false,
  revert: true,
  stash: true,
  verbose: false
} +1ms
lint-staged: Running `lint-staged@16.2.4` on Node.js v22.19.0 (linux) +6ms
lint-staged:execGit: Running git command [ 'version', '--build-options' ] +12ms
lint-staged: git version 2.51.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
libcurl: 8.11.1
OpenSSL: OpenSSL 3.2.4 11 Feb 2025
zlib-ng: 2.2.5
SHA-1: SHA1_DC
SHA-256: SHA256_BLK
default-ref-format: files
default-hash: sha1 +7ms
lint-staged:validateOptions: Validating options... +14ms
lint-staged:validateOptions: Validated options: {
  allowEmpty: false,
  color: true,
  concurrent: true,
  configObject: undefined,
  configPath: './package.json',
  continueOnError: false,
  cwd: undefined,
  debug: true,
  diff: undefined,
  diffFilter: undefined,
  failOnChanges: false,
  hidePartiallyStaged: true,
  hideUnstaged: false,
  maxArgLength: 65536,
  quiet: false,
  relative: false,
  revert: true,
  stash: true,
  verbose: false
} +0ms
lint-staged: Unset GIT_LITERAL_PATHSPECS (was `undefined`) +0ms
lint-staged:runAll: Running all linter scripts... +14ms
lint-staged:runAll: Using working directory `/home/dimait/projects/labs` +0ms
lint-staged:resolveGitRepo: Resolving git repo from `/home/dimait/projects/labs` +15ms
lint-staged:resolveGitRepo: Unset GIT_DIR (was `undefined`) +0ms
lint-staged:resolveGitRepo: Unset GIT_WORK_TREE (was `undefined`) +0ms
lint-staged:execGit: Running git command [ 'rev-parse', '--show-cdup', '--show-toplevel', '--absolute-git-dir' ] +8ms
lint-staged:resolveGitRepo: Resolved git repository top-level directory to be `/home/dimait/projects/labs` +3ms
lint-staged:resolveGitRepo: Resolved git config directory to be `/home/dimait/projects/labs/.git` +0ms
lint-staged:execGit: Running git command [ 'log', '-1' ] +4ms
lint-staged:execGit: Running git command [ 'diff', '--diff-filter=ACMR', '--staged', '--raw', '-z' ] +4ms
lint-staged:searchConfigs: Searching for configuration files... +24ms
lint-staged:searchConfigs: Using single configuration path... +0ms
lint-staged:loadConfig: Loading configuration from `./package.json`... +25ms
lint-staged:loadConfig: Successfully loaded config from `/home/dimait/projects/labs/package.json`:
{ '*.{ts,tsx,js,jsx,vue}': [ 'unknown-command --fix' ] } +8ms
lint-staged:validateConfig: Validating config from `/home/dimait/projects/labs/package.json`... +36ms
lint-staged:validateConfig: Validated config from `/home/dimait/projects/labs/package.json`: +0ms
lint-staged:validateConfig: {
  '*.{ts,tsx,js,jsx,vue}': [
    'unknown-command --fix'
  ]
} +0ms
lint-staged:runAll: Loaded list of staged files in git:
[ { filepath: '/home/dimait/projects/labs/bump.js', status: 'M' } ] +21ms
lint-staged:groupFilesByConfig: Grouping 1 files by 1 configurations +39ms
lint-staged:chunkFiles: Resolved an argument string length of 34 characters from 1 files +45ms
lint-staged:chunkFiles: Creating 1 chunks for maxArgLength of 65536 +0ms
lint-staged:generateTasks: Generating linter tasks +42ms
lint-staged:generateTasks: Generated task: 
{
  pattern: '*.{ts,tsx,js,jsx,vue}',
  commands: [ 'unknown-command --fix' ],
  fileList: [ { filepath: '/home/dimait/projects/labs/bump.js', status: 'M' } ]
} +11ms
lint-staged:getSpawnedTasks: Creating Listr tasks for commands [ 'unknown-command --fix', [length]: 1 ] +55ms
lint-staged:getSpawnedTask: cmd: unknown-command +57ms
lint-staged:getSpawnedTask: args: [ '--fix' ] +0ms
lint-staged:getSpawnedTask: Spawn options: {
  cwd: '/home/dimait/projects/labs',
  preferLocal: true,
  stdin: 'ignore',
  env: { FORCE_COLOR: 'true' }
} +0ms
lint-staged:chunkFiles: Resolved an argument string length of 34 characters from 1 files +18ms
lint-staged:chunkFiles: Creating 1 chunks for maxArgLength of 65536 +0ms
lint-staged:runAll: Set max event listeners to the number of tasks: 1 +27ms
[STARTED] Backing up original state...
lint-staged:GitWorkflow: Backing up original state... +73ms
lint-staged:GitWorkflow: Backing up merge state... +0ms
lint-staged:file: Reading file `/home/dimait/projects/labs/.git/MERGE_HEAD` +74ms
lint-staged:file: Reading file `/home/dimait/projects/labs/.git/MERGE_MODE` +0ms
lint-staged:file: Reading file `/home/dimait/projects/labs/.git/MERGE_MSG` +0ms
lint-staged:file: File `/home/dimait/projects/labs/.git/MERGE_HEAD` doesn't exist, ignoring... +1ms
lint-staged:file: File `/home/dimait/projects/labs/.git/MERGE_MODE` doesn't exist, ignoring... +0ms
lint-staged:file: File `/home/dimait/projects/labs/.git/MERGE_MSG` doesn't exist, ignoring... +0ms
lint-staged:GitWorkflow: Done backing up merge state! +2ms
lint-staged:GitWorkflow: Getting deleted files... +0ms
lint-staged:execGit: Running git command [ 'ls-files', '--deleted' ] +52ms
lint-staged:GitWorkflow: Found deleted files: [] +8ms
lint-staged:GitWorkflow: Getting partially staged files... +0ms
lint-staged:execGit: Running git command [ 'status', '-z' ] +9ms
lint-staged:GitWorkflow: Found partially staged files: [] +9ms
lint-staged:execGit: Running git command [ 'stash', 'create' ] +9ms
lint-staged:execGit: Running git command [ 'rev-parse', '--short', '67a9d4cfde5b0515033e4eac0b5aa761ec586730' ] +8ms
lint-staged:execGit: Running git command [
  'stash',
  'store',
  '--quiet',
  '--message',
  'lint-staged automatic backup',
  '67a9d4c'
] +3ms
lint-staged:GitWorkflow: Backed up original state in git stash (67a9d4c) +16ms
[COMPLETED] Backed up original state in git stash (67a9d4c)
[STARTED] Running tasks for staged files...
[STARTED] package.json — 1 file
[STARTED] *.{ts,tsx,js,jsx,vue} — 1 file
[STARTED] unknown-command --fix
[FAILED] Command failed: unknown-command --fix /home/dimait/projects/labs/bump.js
[FAILED] Command failed: unknown-command --fix /home/dimait/projects/labs/bump.js
[COMPLETED] Running tasks for staged files...
[STARTED] Applying modifications from tasks...
[SKIPPED] Skipped because of errors from tasks.
[STARTED] Reverting to original state because of errors...
lint-staged:GitWorkflow: Restoring original state... +6ms
lint-staged:execGit: Running git command [ 'reset', '--hard', 'HEAD' ] +11ms
file:///home/dimait/.npm/_npx/8facc973fbdb1091/node_modules/nano-spawn/source/result.js:52
        : new SubprocessError(`Command failed: ${command}`, {cause: error});
          ^

SubprocessError: Command failed: unknown-command --fix /home/dimait/projects/labs/bump.js
    at getErrorInstance (file:///home/dimait/.npm/_npx/8facc973fbdb1091/node_modules/nano-spawn/source/result.js:52:4)
    at getResultError (file:///home/dimait/.npm/_npx/8facc973fbdb1091/node_modules/nano-spawn/source/result.js:45:2)
    at spawnSubprocess (file:///home/dimait/.npm/_npx/8facc973fbdb1091/node_modules/nano-spawn/source/spawn.js:32:9)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async getResult (file:///home/dimait/.npm/_npx/8facc973fbdb1091/node_modules/nano-spawn/source/result.js:5:19)
    at async Task.taskFn (file:///home/dimait/.npm/_npx/8facc973fbdb1091/node_modules/lint-staged/lib/getSpawnedTask.js:157:22)
    at async Task.run (file:///home/dimait/.npm/_npx/8facc973fbdb1091/node_modules/listr2/dist/index.js:1905:5) {
  exitCode: undefined,
  signalName: undefined,
  stdout: '',
  stderr: '',
  output: '',
  command: 'unknown-command --fix /home/dimait/projects/labs/bump.js',
  durationMs: 2.959058,
  [cause]: Error: spawn unknown-command ENOENT
      at ChildProcess._handle.onexit (node:internal/child_process:285:19)
      at onErrorNT (node:internal/child_process:483:16)
      at process.processTicksAndRejections (node:internal/process/task_queues:90:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn unknown-command',
    path: 'unknown-command',
    spawnargs: [ '--fix', '/home/dimait/projects/labs/bump.js' ]
  }
}
```



</details>

### Environment

OS: Fedora Linux 42
Node.js v22.19.0
lint-staged: 16.2.4
Continue on GitHub ↗

04 / LABELS

Labels from the report text only; not yet run

No supported category has been assigned.

Label rules and the text that matched
[]