【发布时间】:2022-12-02 03:06:36
【问题描述】:
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:
Expected Behavior
I had a colleague attempt the same step and he was able to get the results I anticipated:
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 installon my simplisticpackage.jsonfile above and on a \'real\'package.jsonfile 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)