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 - pm2 install typescript #2675

Open
kevincollins7 opened this issue Jan 31, 2017 · 35 comments
Open

Windows - pm2 install typescript #2675

kevincollins7 opened this issue Jan 31, 2017 · 35 comments

Comments

@kevincollins7
Copy link

Happening on both Windows 10 and Windows 7.

I have done the following:

npm install pm2 -g
npm install ts-node -g
pm2 install typescript

When I run pm2 start app.ts I get the following:

Interpreter C:\User\Me\AppData\Roaming\npm\node_modules\pm2\node_modules.bin\ts-node does seem to be available

I checked out that directory and sure enough there is nothing named ts-node there. I had a friend on a Mac send me a screenshot of his .bin directory and could tell that there was a ts-node symlink pointed to the ../ts-node/dist/bin.js file. I attempted to created a symlink (in Windows) and that did not fix it.

Is the typescript interpreter working in Windows? Am I missing a step required for Windows? It worked very nicely on my friends Mac.

Global installs:
node@6.7.0
pm2@2.3.0
ts-node@2.0.0
typescript@2.1.5

@kevincollins7
Copy link
Author

From the pm2 log:

2017-01-31 16:29:05: Error: spawn C:\Users\Me\AppData\Roaming\npm\node_modules\pm2\node_modules.bin\ts-node ENOENT
at exports._errnoException (util.js:1036:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)

@vmarchaud
Copy link
Contributor

@kevincollins7 Could you retest with this patch ? (you can use npm install -g Unitech/pm2#development && pm2 update instead of applying the patch yourself)

@kevincollins7
Copy link
Author

@vmarchaud Just tested. Still not working.

The console shows the error:
Interpreter C:\Users\Me\AppData\Roaming\npm\node_modules\pm2\node_modules.bin\ts-node does not seems to be available.

npm ls -g --depth=0 shows the following:
pm2@2.4.0 (git://github.com/unitech/pm2.git#12c9eeaeea105bca4b94f9141458d13c94dacc5f)
ts-node@2.0.0
typescript@2.1.5

npm ERR! extraneous: ts-node@2.0.0 C:\Users\Me\AppData\Roaming\npm\node_modules\pm2\node_modules\ts-node

npm ERR! extraneous: typescript@2.1.5 C:\Users\Me\AppData\Roaming\npm\node_modules\pm2\node_modules\typescript

And finally pm2.log:
2017-02-02 07:16:37: Error: spawn C:\Users\Me\AppData\Roaming\npm\node_modules\pm2\node_modules.bin\ts-node ENOENT
at exports._errnoException (util.js:1036:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)

@vmarchaud
Copy link
Contributor

Could you paste me the ecosystem or CLI command that you are using ?

@kevincollins7
Copy link
Author

You mean the start command?

pm2 start app.ts

image

@Unitech
Copy link
Owner

Unitech commented Feb 2, 2017

Is the ts-node available in the path:
C:\Users\Me\AppData\Roaming\npm\node_modules\pm2\node_modules\.bin\ts-node ?

@Unitech
Copy link
Owner

Unitech commented Feb 2, 2017

When you do

$ npm install ts-node -g

Can you tell me the exact path of the ts-node binary?

btw to resolve the path:
https://github.com/Unitech/pm2/blob/master/lib/Common.js#L369

@kevincollins7
Copy link
Author

No it is not. I do see that there is a ts-node file and a ts-node.cmd in the npm\node-modules\pm2 directory though.

image

image

@kevincollins7
Copy link
Author

It appears to me that the global install "npm install ts-node -g" is placing the the ts-node binary in the npm root. But it appears that PM2 is attempting to find a ts-node binary created after running "pm2 install typescript" correct?

@kevincollins7
Copy link
Author

Also if I change that code you are referencing in the Common.js file to:

if (app.exec_interpreter == 'ts-node') {
app.exec_interpreter = path.join(__dirname, '../ts-node');
}

The error in the console goes away. However the app still errors out and in the .pm2 log I see:

2017-02-02 10:11:49: Error: spawn C:\Users\Kevin\AppData\Roaming\npm\node_modules\pm2\ts-node ENOENT
at exports._errnoException (util.js:1036:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)

@vmarchaud
Copy link
Contributor

Could you retry again please ? Do not forget to pm2 update : npm install -g Unitech/pm2#development && pm2 update

@kevincollins7
Copy link
Author

@vmarchaud No problem. Ran the install and update as you said. Same errors however I noticed that "pm2 install typescript" now installed a typescript and ts-node directory directly in the project. However there is not a .bin folder where it is looking for one.

image

image

pm2.log
2017-02-03 07:47:53: Error: spawn C:\Projects\pm2-test\node_modules.bin\ts-node ENOENT
at exports._errnoException (util.js:1036:11)
at Process.ChildProcess._handle.onexit (internal/child_process.js:193:32)
at onErrorNT (internal/child_process.js:359:16)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickDomainCallback (internal/process/next_tick.js:122:9)

@kevincollins7
Copy link
Author

Wondering if this will help you out? This is the output of "pm2 install typescript"

image

@vmarchaud
Copy link
Contributor

Last hope with 2e6ed64 if its not working you will be on your own to fix this problem, we didn't have any windows to test the issue.

@kevincollins7
Copy link
Author

@vmarchaud Thanks but still not working! I will keep looking into it to see if I can assist. Just so I'm completely understanding though - the goal is for "pm2 start app.ts" to execute a binary ts-node file correct? Was the ts-node interpreter ever tested on Windows before? I have used ts-node by itself and have had no issues so I really think it's just a matter of getting pm2 to find what it's looking for in a Windows environment.

@vmarchaud
Copy link
Contributor

When you use pm2 install typescript, it call this function that npm install into the node_modules folder of pm2 (should be somewhere in C:/Users/user/AppData/npm/lib/pm2) then when you start a .ts file it will automatically set ts-node as interpreter and finally it use the ts-node installed before inside node_modules and start your application with it.

You just need to play with the path used to make it works.

@kevincollins7
Copy link
Author

kevincollins7 commented Feb 3, 2017

@vmarchaud I think I'm on to something. It appears that when "pm2 install typescript" is executed it places a 'ts-node' AND 'ts-node.cmd' file in the pm2 root. I changed the Common.js file like so:

pm2/lib/Common.js line 368
if (app.exec_interpreter == 'ts-node') { app.exec_interpreter = path.join(__dirname, '../ts-node.cmd'); }

That started throwing a bunch of these errors:
Error: EBADF: bad file descriptor, uv_pipe_open

A quick search on Google and I ended up back in the pm2 github for a similar problem where the reporter had said they removed 'ipc' from the ForkMode.js file. https://github.com/Unitech/pm2/issues/2037

pm2/lib/God/ForkMode.js line 98

var cspr = spawn(command, args, { env : pm2_env, detached : true, cwd : pm2_env.pm_cwd || process.cwd(), stdio : ['pipe', 'pipe', 'pipe'] //Same as fork() in node core });

I tried that and it worked! It does open a separate "Node" window which is kind of strange but from what I can tell everything seems to be working. I'm not familiar enough with the inner-workings of pm2 to know how removing 'ipc' from the ForkMode.js file will effect everything else but was hoping that this would help narrow down the issue for you?

@vmarchaud
Copy link
Contributor

IPC is used to communicate with your process to get metrics from it so it isnt possible to remove it.
See #2182 for the popups (can't be fixed).
The workaround for you should be to install ts-node globally and then run your app with --interpreter ts-node

@atrauzzi
Copy link

atrauzzi commented Apr 12, 2017

Just wanted to say I'm experiencing this issue as well. Would love to see it resolved as it might make me unable to use PM2 at all. I know it sounds kind of lame, but you can always set up a preview copy of Windows 10 in a VM.

(trust me, I'm a linux guy, I know how silly the licensing is!)

@ezamelczyk
Copy link

@vmarchaud your workaround is not working at all and the issue is still persisting. I'm experiencing exactly the same behaviour as @kevincollins7
Kevin did you find any working solution for this issue?

@vmarchaud
Copy link
Contributor

We don't have any Windows PC so feel free to make a PR to fix the issue if anyone find a solution :)

@ezamelczyk
Copy link

Then I guess that's not relevant anymore... https://keymetrics.io/2016/08/24/pm2-v2-released/#windowssupport

@vmarchaud
Copy link
Contributor

@ezamelczyk Indeed its not relevant anymore, when i arrived at keymetrics i was working on Windows but one month after i switched to Linux because it's too difficult to work on windows.
Again, PM2 is open source (and free) so you can try to fix the bug by yourself and submit it so it can be fixed for everyone else.

@guzuomuse
Copy link

any progress? same error here with the latest version typescipt pm2 and ts-node.

@milichev
Copy link

Hi, any chance to have it fixed?
Is it possible to run typescript in Windows afterwards?

@toddwong
Copy link
Contributor

toddwong commented Dec 2, 2017

@kevincollins7 I believe this is caused by the fact that .bat/.cmd files are not executable by theirselves on Windows. See node doc https://nodejs.org/dist/latest-v9.x/docs/api/child_process.html#child_process_spawning_bat_and_cmd_files_on_windows

That say, you need pass a shell: process.platform === 'win32' && /\.(cmd|bat)$/i.test(command) (NOT TESTED) option to the spawn call at

pm2/lib/God/ForkMode.js

Lines 94 to 100 in a435f2f

var cspr = spawn(command, args, {
env : pm2_env,
detached : true,
windowsHide: true,
cwd : pm2_env.pm_cwd || process.cwd(),
stdio : ['pipe', 'pipe', 'pipe', 'ipc'] //Same as fork() in node core
});
. Or unshift '/c', command to args and make the cmd.exe as your command.

The same may apply to cluster mode too.

@eran10
Copy link

eran10 commented Mar 28, 2018

Hi, any chance to have it fixed?

@sant123
Copy link

sant123 commented Apr 29, 2018

I'm using Windows 10 and I'm not facing this issue, may you try removing ts-node from global and leave pm2 handle it?

These were my steps to config my env:

  • yarn global add pm2
  • pm2 install typescript

And execute my config file...

pm2 start pm2.json

{
    "apps": [
        {
            "name": "lost-pets",
            "script": "./src/bin/index.ts",
            "watch": ["./src"],
            "instances": 0,
            "exec_mode": "cluster"
        }
    ]
}

image

@aspirisen
Copy link

@sant123 what if "exec_mode": "fork" ?

@sant123
Copy link

sant123 commented May 3, 2018

Ohhhhh got it, sorry I did not try with fork

image

@sant123
Copy link

sant123 commented May 3, 2018

Only cluster works:

image

@ezimnitskiy
Copy link

same problem in fork mode (windows 7)

@eran10
Copy link

eran10 commented Jul 10, 2018

only cluster works for me also, problem is that if i run this command directly (while the service is cluster)
pm2 startOrRestart ecosystem.config.js --only test.ts - it works.
but if i am run it using yarn as a script -e.g yarn start:test (were the script value is the command above) it doesn't work and the process failed.
any idea someone ?

@DifferentialityDevelopment

I am still having this same issue today.
On windows it will not spawn ts-node giving this error
Error: spawn ..\Roaming\npm\node_modules\pm2\node_modules.bin\ts-node ENOENT

I am running WSL2 on my Windows machine and I tried the exact same setup in linux and it works out of the box.
ecosystem config js

on Linux if I run "pm2 start ecosystem.config.js" it correctly starts the application, working 100%.
On Windows if i run the exact same command I get the error mentioned above, I've tried 1000 different solutions online and nothing seems to work, any help would be greatly appreciated.

@andreterron
Copy link

I was able to repro the issue outside of pm2:

PS > node -e "require('child_process').spawn('.\\ts-node', { stdio: 'inherit' })"
events.js:292
      throw er; // Unhandled 'error' event
      ^

Error: spawn .\ts-node ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:269:19)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:275:12)
    at onErrorNT (internal/child_process.js:465:16)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn .\\ts-node',
  path: '.\\ts-node',
  spawnargs: []
}

And adding the shell: true option fixes it:

PS > node -e "require('child_process').spawn('.\\ts-node', { stdio: 'inherit', shell: true })"
> // ts-node REPL

I haven't had time to test inside of pm2, but taking a look at the code, a quick prototype can be done by adding that setting in the options passed to spawn in the file lib\God\ForkMode.js

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