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

Can't start global (or linked) npm module on Windows #2037

Closed
hugomallet opened this issue Mar 22, 2016 · 17 comments
Closed

Can't start global (or linked) npm module on Windows #2037

hugomallet opened this issue Mar 22, 2016 · 17 comments

Comments

@hugomallet
Copy link

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?

@vmarchaud vmarchaud self-assigned this Jul 6, 2016
@vmarchaud
Copy link
Contributor

@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>

@hugomallet
Copy link
Author

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

@vmarchaud
Copy link
Contributor

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

@hugomallet
Copy link
Author

yes @vmarchaud, i have create a gist.

@vmarchaud
Copy link
Contributor

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

@vmarchaud
Copy link
Contributor

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.

@yangg
Copy link

yangg commented Aug 4, 2016

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);
    ^

@vmarchaud
Copy link
Contributor

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

@yangg
Copy link

yangg commented Aug 5, 2016

@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?

@vmarchaud
Copy link
Contributor

@yangg Will try asap

@musahaidari
Copy link

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.

@hbrls
Copy link

hbrls commented Dec 2, 2016

I'm in with docker and the same issue.

@nakamorichi
Copy link

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.

@dkern
Copy link

dkern commented May 5, 2017

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)

@vmarchaud
Copy link
Contributor

vmarchaud commented May 5, 2017

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 :)

@dkern
Copy link

dkern commented May 5, 2017

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

@vmarchaud
Copy link
Contributor

vmarchaud commented May 5, 2017

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

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

No branches or pull requests

8 participants