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

node wrongly searched in relative path #21

Open
OoDeLally opened this issue Sep 12, 2017 · 3 comments
Open

node wrongly searched in relative path #21

OoDeLally opened this issue Sep 12, 2017 · 3 comments

Comments

@OoDeLally
Copy link

OoDeLally commented Sep 12, 2017

Im launching my server this way:

node --expose_gc ./node_modules/.bin/grunt server:local

And get the following error:

Error: Cannot find module '/home/oodelally/backend/node'
    at Function.Module._resolveFilename (module.js:489:15)
    at Function.Module._load (module.js:439:25)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3
module.js:491
    throw err;

So it seems that node is not taken from the environment, but from the current directory.
When executing that command directly on the console, it runs fine.


More details if needed:

package.json:

  "scripts": {
    "start": "node ./code/server/monitor.js node --expose_gc ./node_modules/.bin/grunt server:local"
  }

monitor.js:


'use strict'

const respawn = require('respawn')
const _ = require('lodash')

const args = _.drop(process.argv, 2)

const monitor = respawn(args, {
  name: 'server monitor',    // set monitor name
  env: process.env, // set env vars
  cwd: '.',              // set cwd
  maxRestarts: 10,       // how many restarts are allowed within 60s
                         // or -1 for infinite restarts
  sleep:[1000, 2000, 5000, 10000], // time to sleep between restarts,
  kill:30000,            // wait 30s before force killing after stopping
  stdio: 'pipe',          // forward stdio options
  fork: true             // fork instead of spawn
})

monitor.on('stdout', (data) => {
  process.stdout.write(data)
})

monitor.on('stderr', (data) => {
  process.stderr.write(data)
})

monitor.start() // spawn and watch

process.env.PATH: [...]:/home/oodelally/.nvm/versions/node/v8.4.0/bin/:[...] So node should be available.

@OoDeLally OoDeLally changed the title node searched in relative path node wrongly searched in relative path Sep 12, 2017
@mafintosh
Copy link
Owner

Did you mean to open the issue here? This error is unrelated to respawn

@01binary
Copy link

Just hit the same issue. The source of the confusion is that when fork: true is set, respawn tries to load a node module instead of launching an executable. I don't understand why.

i.e. error above occurs because the author is expecting respawn to find node.exe, but respawn is actually looking for a node module called node.js in current directory, PATH, and any other directory it checks for node modules.

@01binary
Copy link

Confirmed that adding fork option does change the API entirely, so you are supposed to specify node module name as target, and it's possible to pass Node path and Node args separately in options for fork (see docs).

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

3 participants