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

windows: spawn npm ENOENT #43

Open
tswaters opened this issue Aug 13, 2017 · 1 comment
Open

windows: spawn npm ENOENT #43

tswaters opened this issue Aug 13, 2017 · 1 comment

Comments

@tswaters
Copy link

When using the following for a start command under windows,

service:
  type: process
  path: ./service
  run: 'npm start'

The following is returned when attempting to start:

fuge> [service] exit - status: crashed duration: 11

Adding the following reveals the actual error:

diff --git a/lib/system.js b/lib/system.js
index 3c1fe90..8d1b8ae 100644
--- a/lib/system.js
+++ b/lib/system.js
@@ -60,6 +60,7 @@ module.exports = function () {

     _.each(history, function (h) {
       if (h.endTime > mark && h.exitFlag === CRASHED) {
+        console.log(h.exitData.err)
         ++crashCount
       }
     })

It is:

{ Error: spawn npm ENOENT
    at exports._errnoException (util.js:1024:11)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:192:19)
    at onErrorNT (internal/child_process.js:374:16)
    at _combinedTickCallback (internal/process/next_tick.js:138:11)
    at process._tickCallback (internal/process/next_tick.js:180:9)
  code: 'ENOENT',
  errno: 'ENOENT',
  syscall: 'spawn npm',
  path: 'npm',
  spawnargs: [ 'start' ] }

It seems that windows wants npm.cmd as the start command, which obviously isn't ideal. There is a long-standing issue in the old node archive repo that addresses this: nodejs/node-v0.x-archive#2318. The short end of the stick is the .cmd can be omitted if shell: true is added to the spawn args, here:

diff --git a/lib/support/processRunner.js b/lib/support/processRunner.js
index 72f06b4..c60be6b 100644
--- a/lib/support/processRunner.js
+++ b/lib/support/processRunner.js
@@ -58,7 +58,7 @@ module.exports = function () {
     }

     if (mode !== 'preview') {
-      var options = {cwd: cwd, env: env, stdio: ['ignore', 'pipe', 'pipe'], detached: false}
+      var options = {cwd: cwd, env: env, stdio: ['ignore', 'pipe', 'pipe'], detached: false, shell: true}
       if (container.type === 'node' && !isWin) {
         options.stdio[3] = 'ipc'
       }

I'm not sure if this would adversely affect things, so I ran the tests....

There are currently two tests failing in windows, under test/runner.test.js -- check grep result and check grepall result are returning 0.... excluding those, with this change, there is only 1 test failure.... under processRunner.test.js, the process fail test isn't running null for child.id

If not sure why this is, but I tried recreated the same conditions using fuge with this change, and it seems to still work (a process.exit(1) after a timeout is still handled properly)

@pelger
Copy link
Contributor

pelger commented Aug 17, 2017

Thanks for the detailed report and investigation - much appreciated! Will take a look at this tomorrow or at the weekend and revert once fixed.

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

No branches or pull requests

2 participants