npm-run icon indicating copy to clipboard operation
npm-run copied to clipboard

ENOENT error on Windows

Open eight04 opened this issue 7 years ago • 9 comments

D:\Dev\webextension-test>npm-run --version
5.0.1

D:\Dev\webextension-test>npm-run web-ext --version
Error: spawn web-ext ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:201:19)
    at onErrorNT (internal/child_process.js:379:16)
    at process._tickCallback (internal/process/next_tick.js:114:19)
    at Function.Module.runMain (module.js:705:11)
    at startup (bootstrap_node.js:193:16)
    at bootstrap_node.js:660:3

D:\Dev\webextension-test>npm-run where web-ext
D:\Dev\webextension-test\node_modules\.bin\web-ext
D:\Dev\webextension-test\node_modules\.bin\web-ext.cmd
C:\Users\Owner\AppData\Roaming\npm\web-ext
C:\Users\Owner\AppData\Roaming\npm\web-ext.cmd

It works fine with v4.x.

eight04 avatar Apr 16 '18 09:04 eight04

What version of node?

timoxley avatar Apr 16 '18 14:04 timoxley

Node.js v9.7.1 Windows 7 x64

eight04 avatar Apr 17 '18 04:04 eight04

Ok so I had to pull the execSync polyfill due to a security issue reported in #16, will have to look into alternatives for windows, at least getting this running on the cli. Apologies, for windows I recommend continuing to use 4.x for now.

timoxley avatar Apr 18 '18 06:04 timoxley

Feel free to do some investigation and send a PR, might be a few days until I get around to looking at it.

timoxley avatar Apr 18 '18 06:04 timoxley

I think that on Windows, only executables (.exe) are spawn-able without extension name. Here is a test script:

async function test() {
  const {spawn} = require("child_process");
  const eventToPromise = require("event-to-promise");
  let p;
  p = spawn("where", ["web-ext"], {stdio: "inherit"});
  await eventToPromise(p, "exit");
  
  p = spawn("where.exe", ["web-ext"], {stdio: "inherit"});
  await eventToPromise(p, "exit");
  
  p = spawn("web-ext", ["--version"], {stdio: "inherit"});
  try {
    await eventToPromise(p, "exit");
  } catch (err) {
    console.log("spawn error", err);
  }
  
  p = spawn("web-ext.cmd", ["--version"], {stdio: "inherit"});
  await eventToPromise(p, "exit");
  
  p = spawn("web-ext", ["--version"], {stdio: "inherit", shell: true});
  await eventToPromise(p, "exit");
  
  p = spawn("web-ext", ["--version"], {stdio: "inherit", shell: true, env: {pathext: ";"}});
  try {
    await eventToPromise(p, "exit");
  } catch (err) {
    console.log("spawn error", err);
  }
}

test();
C:\Users\Owner\AppData\Roaming\npm\web-ext
C:\Users\Owner\AppData\Roaming\npm\web-ext.cmd
C:\Users\Owner\AppData\Roaming\npm\web-ext
C:\Users\Owner\AppData\Roaming\npm\web-ext.cmd
spawn error { Error: spawn web-ext ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:201:19)
    at onErrorNT (internal/child_process.js:379:16)
    at process._tickCallback (internal/process/next_tick.js:114:19)
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn web-ext',
  path: 'web-ext',
  spawnargs: [ '--version' ] }
2.6.0
2.6.0
'web-ext' 不是內部或外部命令、可執行的程式或批次檔。

To correctly spawn a .cmd file, we have to use the full name, or invokes it through the shell that relies on environment variable pathext.

Also note that, by spawning through shell, even the command isn't found, the child process (the shell process i.e. cmd.exe) is spawned successfully.

I would like to add options.shell = true here: https://github.com/timoxley/npm-run/blob/03d91cb860427265a4b22fe60e8001ccf4de688c/index.js#L54-L61 What do you think?

eight04 avatar Apr 18 '18 07:04 eight04

I am too facing the same issue.

Posting the error log here.

> [email protected] build-html:ecart-static-ui C:\Users\Lakky69\ecart\dev-tools\api-doc
> npm-run raml2html ecart-static-ui/index.raml -o  dist/ecart-static-ui.html
Error: spawn raml2html ENOENT
    at exports._errnoException (util.js:1020:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:197:32)
    at onErrorNT (internal/child_process.js:376:16)
    at _combinedTickCallback (internal/process/next_tick.js:80:11)
    at process._tickCallback (internal/process/next_tick.js:104:9)
    at Module.runMain (module.js:606:11)
    at run (bootstrap_node.js:389:7)
    at startup (bootstrap_node.js:149:9)
    at bootstrap_node.js:502:3
npm ERR! code ELIFECYCLE
npm ERR! errno 4294963238
npm ERR! [email protected] build-html:ecart-static-ui: `npm-run raml2html ecart-static-ui/index.raml -o  dist/ecart-static-ui.html`
npm ERR! Exit status 4294963238
npm ERR!
npm ERR! Failed at the [email protected] build-html:ecart-static-ui script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Lakky69\AppData\Roaming\npm-cache\_logs\2018-04-20T09_43_34_743Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 4294963238
npm ERR! [email protected] build:ecart-static-ui: `npm run build-html:ecart-static-ui && npm run build-md:ecart-static-ui`
npm ERR! Exit status 4294963238
npm ERR!
npm ERR! Failed at the [email protected] build:ecart-static-ui script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Lakky69\AppData\Roaming\npm-cache\_logs\2018-04-20T09_43_34_806Z-debug.log

senthilps avatar Apr 23 '18 06:04 senthilps

@eight04 so hang on, does adding shell: true fix the issue?

timoxley avatar Apr 25 '18 02:04 timoxley

@timoxley Yes, it does.

diff --git a/index.js b/index.js
index c7925c6..5d79520 100644
--- a/index.js
+++ b/index.js
@@ -57,6 +57,7 @@ function augmentOptionsSync (options) {
   var env = Object.create(options.env)
   env[npmPath.PATH] = newPath
   options.env = env
+  options.shell = true
   return options
 }
 

D:\Dev\webextension-test>npm-run --version
5.0.1

D:\Dev\webextension-test>npm-run web-ext --version
2.6.0

Also the test failed on Windows:

D:\Dev\npm-run>npm test

> [email protected] test D:\Dev\npm-run
> tape test/*.js && npm run lint

TAP version 13
# bin ok
ok 1 should be truthy
ok 2 bin exists: D:\Dev\npm-run\bin\npm-run.js
# passing dashed args
internal/child_process.js:330
    throw errnoException(err, 'spawn');
    ^

Error: spawn UNKNOWN
    at ChildProcess.spawn (internal/child_process.js:330:11)
    at exports.spawn (child_process.js:500:9)
    at Test.<anonymous> (D:\Dev\npm-run\test\bin.js:26:15)
    at Test.bound [as _cb] (D:\Dev\npm-run\node_modules\tape\lib\test.js:77:32)
    at Test.run (D:\Dev\npm-run\node_modules\tape\lib\test.js:96:10)
    at Test.bound [as run] (D:\Dev\npm-run\node_modules\tape\lib\test.js:77:32)
    at Immediate.next (D:\Dev\npm-run\node_modules\tape\lib\results.js:71:15)
    at runCallback (timers.js:763:18)
    at tryOnImmediate (timers.js:734:5)
    at processImmediate (timers.js:716:5)
npm ERR! Test failed.  See above for more details.

eight04 avatar Apr 25 '18 13:04 eight04

Any ideas on this one? I can support in pushing this forward.

divyenduz avatar May 31 '18 12:05 divyenduz