Skip to content

windows: spawn npm ENOENT #43

Description

@tswaters

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions