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

issue with ts-node on Windows #4962

Open
leolivier opened this issue Jan 16, 2021 · 1 comment
Open

issue with ts-node on Windows #4962

leolivier opened this issue Jan 16, 2021 · 1 comment

Comments

@leolivier
Copy link

leolivier commented Jan 16, 2021

What's going wrong?

When running pm2 start with a ts-node script on Windows 10, I get an error inside ts-node. I don't have the issue when running the ts-node command directly from a Powershell

How could we reproduce this issue?

My ecosystem contains:

module.exports = {
  apps : [{
    name: 'pier-admin-development',
    script: './node_modules/.bin/ts-node-dev',
    watch: '.',
    exec_mode: 'fork',
    args: '--files ./src/main.ts',
    max_memory_restart: '150M',
    time: true, // add time to logs
  }]
};

Running pm2 start gives:

[PM2][WARN] Applications pier-admin-development not running, starting...
[PM2] App [pier-admin-development] launched (1 instances)
┌─────┬───────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ pier-admin-development    │ default     │ 1.0.0   │ fork    │ 2248     │ 0      │ 1    │ stopped   │ 0%       │ 0b       │ olivi    │ enabled  │
└─────┴───────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

(status=stopped and not errored) and pm2 logs:

PS D:\devts\pier\pier-admin-develop> pm2 logs
[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)
C:\Users\olivi\.pm2\logs\pier-admin-development-out.log last 15 lines:
C:\Users\olivi\.pm2\logs\pier-admin-development-error.log last 15 lines:
0|pier-adm | 2021-01-16T17:31:32: D:\devts\pier\pier-admin-develop\node_modules\.bin\ts-node-dev:2
0|pier-adm | 2021-01-16T17:31:32: basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
0|pier-adm | 2021-01-16T17:31:32:           ^^^^^^^
0|pier-adm | 2021-01-16T17:31:32:
0|pier-adm | 2021-01-16T17:31:32: SyntaxError: missing ) after argument list
0|pier-adm | 2021-01-16T17:31:32:     at wrapSafe (internal/modules/cjs/loader.js:979:16)
0|pier-adm | 2021-01-16T17:31:32:     at Module._compile (internal/modules/cjs/loader.js:1027:27)
0|pier-adm | 2021-01-16T17:31:32:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|pier-adm | 2021-01-16T17:31:32:     at Module.load (internal/modules/cjs/loader.js:928:32)
0|pier-adm | 2021-01-16T17:31:32:     at Function.Module._load (internal/modules/cjs/loader.js:769:14)
0|pier-adm | 2021-01-16T17:31:32:     at Object.<anonymous> (C:\Users\olivi\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
0|pier-adm | 2021-01-16T17:31:32:     at Module._compile (internal/modules/cjs/loader.js:1063:30)
0|pier-adm | 2021-01-16T17:31:32:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
0|pier-adm | 2021-01-16T17:31:32:     at Module.load (internal/modules/cjs/loader.js:928:32)
0|pier-adm | 2021-01-16T17:31:32:     at Function.Module._load (internal/modules/cjs/loader.js:769:14)

but running directly D:\devts\pier\pier-admin-develop\node_modules\.bin\ts-node-dev --files ./src/main.ts works fine...
EDIT: The same config works on Linux (Ubuntu & Raspbian)

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Sat Jan 16 2021 17:52:49 GMT+0100 (heure normale d’Europe centrale)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 4.5.0
node version         : 14.15.0
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\olivi\AppData\Roaming\npm\node_modules\pm2\lib\Daemon.js
argv0                : node
user                 : undefined
uid                  : N/A
gid                  : N/A
uptime               : 46min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 4.5.0
node version         : 14.15.0
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\olivi\AppData\Roaming\npm\node_modules\pm2\bin\pm2,report
argv0                : C:\Program Files\nodejs\node.exe
user                 : olivi
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : win32
type                 : Windows_NT
cpus                 : Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
cpus nb              : 8
freemem              : 1679581184
totalmem             : 16953622528
home                 : C:\Users\olivi
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name                      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼───────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ pier-admin-development    │ default     │ 1.0.0   │ fork    │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ olivi    │ enabled  │
└─────┴───────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------

(I looked at #2675 but does not seem to be related)

@leolivier
Copy link
Author

Got it: it's a matter of interpreter. The interperter is guessed automatically on Linux, not on Windows.
Furthermore, ts-node is a shell script ==> you must guess what is your shell interpreter in powershell.
I found one and added it in the ecosystem file:
interpreter: "C:\Program Files\Git\bin\bash.exe",
then it worked but there's a big drawback: I can't get that working on Linux anymore (prod envt).
And I don't understand why ts-node runs in a powershell terminal (it doesn't know the git shell)
Is there a way to define the interpreter differently depending on the OS ?

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

1 participant