Pm2: Can't start global (or linked) npm module on Windows

Created on 22 Mar 2016  路  17Comments  路  Source: Unitech/pm2

Hello,

Config:
Windows 7 / 10
PM2 1.0.2
Node 4.4.0 / 5.9.0

On Windows,

when starting a linked npm "bin" with:

pm2 start <npm module>

the following error is thrown:

SyntaxError: Unexpected token ILLEGAL
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Function._load (node_modules\pm2\node_modules\pmx\lib\transaction.js:62:21)
    at Object.<anonymous> (node_modules\pm2\lib\ProcessContainerFork.js:41:21)
    at Module._compile (module.js:398:26)
    at Object.Module._extensions..js (module.js:405:10)
    at Module.load (module.js:344:32)

The issue seems to come from the chosen interpreter (node). The file which is executed in node is the generated .CMD file.

So we tried to change the script with:

pm2 start cmd.exe -- /c <npm module>

/c option is not correctly interpreted so we decided to try directly in the pm2 forkMode.js file:

// ForkMode.js:91
 var cspr = spawn('cmd', ['/c', '<npm module>'], {
          env      : pm2_env,
          detached : true,
          cwd      : pm2_env.pm_cwd || process.cwd(),
          stdio    : ['pipe', 'pipe', 'pipe', 'ipc'] //Same as fork() in node core
        });

At this point we got the following error:

Error: EBADF: bad file descriptor, uv_pipe_open
    at Error (native)
    at Object.exports._forkChild (child_process.js:61:5)
    at Function.startup.processChannel (node.js:856:10)
    at startup (node.js:45:15)
    at node.js:980:3
 child_process.js:61
  p.open(fd);

Removing 'ipc' on fd 3 solves the problem.

Any idea to fix this?

Won't fix Daemon Windows Bug

Most helpful comment

I suddenly got this issue also in Windows 10. Currently running pm2 2.4.2, but same issue with previous versions:

Error: EBADF: bad file descriptor, uv_pipe_open
    at Error (native)
    at Object.exports._forkChild (child_process.js:65:5)
    at Object.setupChannel (internal/process.js:239:8)
    at startup (bootstrap_node.js:61:16)
    at bootstrap_node.js:509:3

The error goes away if I switch from fork to cluster mode.

All 17 comments

@hugomallet Can you try on the lastest version of pm2 ? This should be fixed since then :

npm remove pm2 -g
npm cache clean
npm install Unitech/pm2#development -g
pm2 update
pm2 start <module>

@vmarchaud i still have the same error (pm2 v2.0.1).

@hugomallet do you have a sample code to reproduce this ?

yes @vmarchaud, i have create a gist.

@hugomallet Will look into this when i can access my windows setup, will keep you up to date with the issue :)

Looked into it, able to reproduce your problem, but i cant see any solution except go into your module folder and start it directly with pm2 start <entrypoint.js> since you need IPC to communicate between PM2 deamon and the process.

Same error when I start gulp watch on windows (the same on development branch)

Error: EBADF: bad file descriptor, uv_pipe_open
    at Error (native)
    at Object.exports._forkChild (child_process.js:61:5)
    at Object.setupChannel (internal/process.js:241:8)
    at startup (node.js:61:16)
    at node.js:456:3
child_process.js:61
  p.open(fd);
    ^

@yangg Can you try to start a app script like this one ? (dont sure its working, dont have any gulp project to test )

@vmarchaud still not work, and no log files output.
It seems has nothing to do with watch, would you like to try gulp with this project?

@yangg Will try asap

Hello,

Just to mention, I have this issue too, using the programmatic API and stand alone version. http://stackoverflow.com/questions/40481215/failing-to-use-pm2-on-windows

Just in case it helps solving the problem.

I'm in with docker and the same issue.

I suddenly got this issue also in Windows 10. Currently running pm2 2.4.2, but same issue with previous versions:

Error: EBADF: bad file descriptor, uv_pipe_open
    at Error (native)
    at Object.exports._forkChild (child_process.js:65:5)
    at Object.setupChannel (internal/process.js:239:8)
    at startup (bootstrap_node.js:61:16)
    at bootstrap_node.js:509:3

The error goes away if I switch from fork to cluster mode.

Came across this problem today. Message is a bit different, but it's a npm linked execution too. 馃槶

SyntaxError: Invalid or unexpected token
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Object.<anonymous> (C:\Users\*\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:53:21)
    at Module._compile (module.js:570:32)
    at Object.Module._extensions..js (module.js:579:10)

For everyone finding this issue, we don't plan to fix this because we have no idea how to so.
If anyone find a solution that works and keep the IPC fd open we will fix this :)

Thanks for the info @vmarchaud !
Just to be sure, is there a known work around for this or parameter fixing the problem?

@eisbehr- Check the content of the issue, @hugomallet posted a fix but it remove the IPC communication so some feature doesn't work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alexpts picture alexpts  路  3Comments

jubairsaidi picture jubairsaidi  路  3Comments

chaos-git picture chaos-git  路  3Comments

shaunwarman picture shaunwarman  路  3Comments

waygee picture waygee  路  4Comments