testdouble / scripty

Because no one should be shell-scripting inside a JSON file.
MIT License
963 stars 23 forks source link

Issue while running scripty on windows10 #92

Open vsawant1608 opened 3 years ago

vsawant1608 commented 3 years ago

I have below package.json file

{
  "name": "scripty-issue",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "node app.js",
    "foo": "scripty"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cross-spawn": "^7.0.3",
    "express": "^4.17.1"
  },
  "devDependencies": {
    "scripty": "^2.0.0"
  },
  "scripty": {
    "logLevel": "verbose"
  }
}

and below is '/scripts/foo.sh'

echo "Hello";

When I run npm run foo getting below error on windows.

internal/child_process.js:366
    throw errnoException(err, 'spawn');
    ^

Error: spawn UNKNOWN
    at ChildProcess.spawn (internal/child_process.js:366:11)
    at spawn (child_process.js:551:9)
    at module.exports (D:\Explore\scripty-issue\node_modules\scripty\lib\run\spawn-script.js:8:17)
    at cb (D:\Explore\scripty-issue\node_modules\scripty\lib\run\index.js:4:27)
    at D:\Explore\scripty-issue\node_modules\async\dist\async.js:3880:24
    at replenish (D:\Explore\scripty-issue\node_modules\async\dist\async.js:1011:17)
    at D:\Explore\scripty-issue\node_modules\async\dist\async.js:1016:9
    at eachOfLimit (D:\Explore\scripty-issue\node_modules\async\dist\async.js:1041:24)
    at D:\Explore\scripty-issue\node_modules\async\dist\async.js:1046:16
    at _parallel (D:\Explore\scripty-issue\node_modules\async\dist\async.js:3879:5)

Just works fine on ubuntu. Any pointers would be helpful. I tried passing {shell:true} in node_modules\scripty\lib\run\spawn-script.js:8:17 and it just worked fine.

GiancarlosIO commented 3 years ago

Same here 😢

magnus-bb commented 3 years ago

Same here. Have tried clearing NPM cache and clearing out node_modules. Scripty exclaims that it can find the script and tries to execute it. The script is executable and works when run directly with bash.

sanketphansekar commented 3 years ago

@vsawant1608 I feel the mistake might be in creating the script file, it should be with extension .cmd

As per documentation : In order to add Windows support, you could define scripts-win/script.cmd

For more details on windows support you can read it here

dealvz commented 3 years ago

@sanketphansekar followed those instructions, however what if the script is type #!/usr/bin/env node ?

jonrcrowell commented 3 years ago

I was having the same issue regardless of how I configured the shebang. (node, cmd, pwsh, bash, whatever) I also deleted node_modules, any .lock files I had, and re-ran yarn.

I was able to get it to work by running wsl from the terminal, then running my scripty script. I have both a /scripts folder and a /scripts-win folder. The version that gets called from the wsl prompt is the /scripts version, which I actually prefer so that I don't have to maintain two sets of scripts.

Unfortunately using wsl only gets past the initial events.js // Unhandled 'error'. My initial test script just had a console.log statement in it. When I added something that I actually want the script to do, it failed.

Changing my node scripts to .cmd files resolved all errors, but left me stuck with re-writing my scripts, which at this point isn't worth the trouble. I want to use JavaScript.

Issues like this make me seriously consider switching to a Mac for good.

vsawant1608 commented 3 years ago

Just a hack for this would be to update file in node_modules to use cross_spawn(https://www.npmjs.com/package/cross-spawn). It makes most of the things work fine on windows without any issues.

image

andredezzy commented 10 months ago

Any news?