Open charleylla opened 5 years ago
Yeah I also had some trouble, the dirty way is the easiest way and for me it works. Forget about interpreter, interpreter_args, args, just all put it in the script value:
script: './node_modules/.bin/ts-node -r tsconfig-paths/register ./src/main.ts'
Yeah I also had some trouble, the dirty way is the easiest way and for me it works. Forget about interpreter, interpreter_args, args, just all put it in the script value:
script: './node_modules/.bin/ts-node -r tsconfig-paths/register ./src/main.ts'
not good
pm2 start bootstrap.js --node-args="-r tsconfig-paths/register"
pm2 start bootstrap.js --node-args="-r tsconfig-paths/register"
@charleylla
For those still having troubles with pm2 obscure arguments handling you can use this solution: https://github.com/Unitech/pm2/issues/4528#issuecomment-753464213 (
This is might not be the most elegant way to handle it, but hey, it just works and is simple and straightforward.
On my case it was a little bit more complex because I was pointing to JS in production (so my tsconfig.json needed to use baseUrl as ./dist/src and not ./src). Locally I'm running on TS, so the issue was only in prod.
To solve it...
my package.json
"start:prod": "pm2 start pm2.json --no-daemon",
my pm2.json - I had to add a custom register-paths.js file here, on my node_args
{
"apps": [
{
"name": "psa-api",
"script": "./dist/src/server.js",
"merge_logs": true,
"max_restarts": 20,
"instances": 4,
"node_args": "-r dotenv/config -r ./register-paths.js"
}
]
}
register-path.js file
const path = require("path");
const tsConfig = require("./tsconfig.json");
const tsConfigPaths = require("tsconfig-paths");
const baseUrl = tsConfig.compilerOptions.baseUrl || ".";
const outDir = tsConfig.compilerOptions.outDir || ".";
const env = process.env.ENV;
let baseUrlPath;
if (env === "Production" || env === "Staging") {
baseUrlPath = path.resolve(outDir, baseUrl);
} else {
baseUrlPath = baseUrl;
}
const explicitParams = {
baseUrl: baseUrlPath,
paths: tsConfig.compilerOptions.paths,
};
tsConfigPaths.register(explicitParams);
Hope it helps! It took me 2 hours to figure it out. :)
For those still having troubles with pm2 obscure arguments handling you can use this solution: Unitech/pm2#4528 (comment) (
This is might not be the most elegant way to handle it, but hey, it just works and is simple and straightforward.
This worked for me on getting pm2 to work with tsconfig-paths/register, Thank you
I'm trying to deploy my typescript project with pm2, but the argument seems not working correctly.
Here is ecosystem.config.yml:
When I run pm2 start ecosystem.config.yml and check the logs then:
And my tsconfig.json is:
It seems that the paths alias are not working properly. It works well without pm2(this is a nestjs project):
Can anyone help me with this problem? Thanks.