Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENOENT error on Windows #19

Open
eight04 opened this issue Apr 16, 2018 · 9 comments · May be fixed by #21
Open

ENOENT error on Windows #19

eight04 opened this issue Apr 16, 2018 · 9 comments · May be fixed by #21

Comments

@eight04
Copy link

eight04 commented Apr 16, 2018

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.

@timoxley
Copy link
Owner

What version of node?

@eight04
Copy link
Author

eight04 commented Apr 17, 2018

Node.js v9.7.1
Windows 7 x64

@timoxley
Copy link
Owner

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
Copy link
Owner

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

@eight04
Copy link
Author

eight04 commented Apr 18, 2018

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:

npm-run/index.js

Lines 54 to 61 in 03d91cb

function augmentOptionsSync (options) {
options = options || {}
var newPath = npmPath.getSync(options)
var env = Object.create(options.env)
env[npmPath.PATH] = newPath
options.env = env
return options
}

What do you think?

@senthilps
Copy link

I am too facing the same issue.

Posting the error log here.

> api-doc@1.0.0 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! api-doc@1.0.0 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 api-doc@1.0.0 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! api-doc@1.0.0 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 api-doc@1.0.0 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

@timoxley
Copy link
Owner

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

@eight04
Copy link
Author

eight04 commented Apr 25, 2018

@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

> npm-run@5.0.1 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.

@divyenduz
Copy link

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

timsuchanek pushed a commit to Urigo/graphql-cli that referenced this issue Jun 1, 2018
* fix: make codegen more robust

* fix: codegen, improve error messages

* fix: codegen, downgrade npm-run to support windows

* fix: codegen, ignore npm-run in renovate bot

npm-run 5.x is broken on windows

we don't want to accidently merge it unless
timoxley/npm-run#19 is resolved.

* fix: codegen, improve error message for graphql-binding

* fix lint
timsuchanek pushed a commit to prisma/prisma1 that referenced this issue Jun 1, 2018
timsuchanek pushed a commit to prisma/prisma1 that referenced this issue Jun 5, 2018
cmcinroy pushed a commit to cmcinroy/prisma that referenced this issue Jun 11, 2018
yaacovCR added a commit to yaacovCR/npm-run that referenced this issue Nov 14, 2018
@yaacovCR yaacovCR linked a pull request Nov 14, 2018 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants