question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

'lint-staged' is not recognized as an internal or external command, operable program or batch file. (Windows)

See original GitHub issue

Description

When using cmd.exe or Visual Studio Code in Windows I get the error “‘lint-staged’ is not recognized as an internal or external command, operable program or batch file.” when I attempt to commit my changes. Essentially the pre-commit fails because of this. This error does not occur in the Windows Subsystem for Linux command prompt.

Steps to reproduce

  1. Insure you are on a Windows machine with git installed.
  2. Create a project that uses lint-staged
  3. Make a change to your repo.
  4. Using Visual Studio Code or simply cmd.exe, attempt to commit your changes.
  5. You should see the error mentioned above in the console.

Debug Logs

expand to view
> git commit --quiet --allow-empty-message --file -
> git show :package.json
husky > npm run -s precommit (node v8.10.0)

'lint-staged' is not recognized as an internal or external command,
operable program or batch file.

husky > pre-commit hook failed (add --no-verify to bypass)
> git config --get-all user.name
> git config --get-all user.email

Environment

  • OS: Windows 10
  • Node.js: v8.10.0
  • lint-staged: v7.0.0

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:8
  • Comments:20 (1 by maintainers)

github_iconTop GitHub Comments

27reactions
nicogreenarrycommented, May 22, 2019

tl;dr: You might run into this problem on WSL if you’re using an IDE or other tool that is making your commit for you, and that tool uses a Windows version of node/npm.


I’m not sure if this solution will be relevant for some of the other folks in this thread, but I figured out what was going on for me. I noted in my previous comment that I’m using WSL, and that I’m able to commit from the command line, but that Webstorm gives the 'lint-staged' is not recognized error.

I realized it’s because my command line uses a version of node and npm installed on the Windows side of things, not installed in the WSL directories. I ran npm install -g lint-staged in my windows terminal (not in ConEmu, which I have set up to use Fish on WSL). Then I was able to commit normally from Webstorm.

I’m still not completely sure why I needed to install lint-staged globally - I thought that npm scripts would search the local node_modules directory when resolving commands. Anyway, it works fine now.

22reactions
zorzystycommented, Nov 25, 2019

Thanks @oturpe for the recap - especially workaround no.3. I added npx to every command in husky config (except git related of course). So instead of

"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "./src/**/*.{js,jsx}": [
      "prettier --write",
      "eslint",
      "git add"
    ]
  }

i did:

"husky": {
    "hooks": {
      "pre-commit": "npx lint-staged"
    }
  },
  "lint-staged": {
    "./src/**/*.{js,jsx}": [
      "npx prettier --write",
      "npx eslint",
      "git add"
    ]
  }

Worked like a charm!

Read more comments on GitHub >

github_iconTop Results From Across the Web

lint-staged not running on precommit - Stack Overflow
this script will create a .husky folder to your working directory and adds pre-commit file to it with script npm run lint-fix to...
Read more >
lint-staged - npm
Run linters against staged git files and don't let slip into your code base! npm install --save-dev lint-staged # requires further setup.
Read more >
'lint-staged' is not recognized as an internal or external ...
'lint-staged' is not recognized as an internal or external command, operable program or batch file. (Windows)
Read more >
How to Fix “not recognized as an internal or external ...
The second possible reason the “not recognized as an internal or external command” occurs is that you don't have the appropriate program ......
Read more >
lint-staged tslint
'lint-staged' is not recognized as an internal or external command, operable program or batch file. > git commit --quiet --allow-empty-message --file ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found