3

Overview

I am attempting to troubleshoot why I can't run scripts defined in a package.json file via npm run command. Every script command returns the same error message:

npm ERR! code ENOENT
npm ERR! syscall spawn bash
npm ERR! path C:\Temp\test4
npm ERR! errno -4058
npm ERR! enoent spawn bash ENOENT
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

Minimal Repro Steps

I installed NodeJS 18.12.1 x64 MSI from the Node Download Page on my Windows 11 machine.

I created an empty directory (called test4 in my example here) with a single file called package.json with the following content:

{
  "scripts": {
    "hello": "echo 'Hello World'"
  }
}

I opened a PowerShell window as administrator inside the same folder as the package.json file listed above.

Running npm run hello generates the error message above.

Verbose/Silly Logging Results

One troubleshooting techniques I used was to enable silly logging to log as many details as possible. The results of that command (npm run hello -ddd) are below:

Screenshot of detailed logging

Expected Behavior

I had a colleague attempt the same step and he was able to get the results I anticipated: Screenshot of command working

Things I Have Already Tried

  • Completely uninstalling NodeJs/NPM following this StackOverflow answer

  • Installing different version of NodeJS/NPM. (I tried 2/3 different versions)

  • Running npm install on my simplistic package.json file above and on a 'real' package.json file from one of my projects. Both projects install successfully.

  • Reviewed the log file mentioned in the error message referring to the AppData folder. (It's the same content as the verbose error screenshot I provided above)

Josh Schultz
  • 897
  • 1
  • 13
  • 32

1 Answers1

4

Run npm config list and check if script-shell is set:

npm config list results

In my case, it was configured to use bash, which is why the error was happening. To solve this, simply remove the configuration setting by running npm config delete script-shell

As to why/how this got set, I am unsure.

Josh Schultz
  • 897
  • 1
  • 13
  • 32
  • Thank you, this helped me. You could also remove the `script-shell = "bash"` line from .npmrc file in your windows user root. – Floris Mar 28 '23 at 18:37