In [email protected] --inspect parameter does not work anymore. It was working in previous ts-node version.
I am having same issue. Nothing about --inspect was mentioned in changelog either.
node --inspect -r ts-node/register path/to/ts
That鈥檚 the intent. Please check the README or change log or more info and use the node command above for inspecting and other node.js flags.
Unfortunately this solution does not work with pm2, which uses ts-node by default to run typescript and passes arguments to ts-node via node_args property.
Can you provide a reference or code snippet so I can verify that claim? Seems like a simple thing to fix.
Hi,
lets assume we have ts-node installed locally via npm and very simple app-test to run:
let fun = () => {console.log('app.js'); setTimeout(fun, 1000);};
fun();
Normally to run and debug app using node:
node --inspect=7000 app-test.js //works OK with debugger
node --inspect=7000 -r ts-node/register app-test.ts //works OK with debugger
To run and debug using pm2 (without typescript installed internally in pm2):
pm2 start --node-args="--inspect=7000" app-test.js //works OK with debugger
pm2 start app-test.ts // does not work
pm2 start --node-args="--inspect=7000 -r ts-node/register" app-test.ts // does not work
Last two examples do not work, because by default pm2 uses ts-node interpreter to run typescript -> https://github.com/Unitech/pm2/blob/master/lib/API/interpreter.json
If we install typescript in pm2 by: _pm2 install typescript_ it also installs the latest version of ts-node.
So now we can normally start our script like this:
pm2 start app-test.ts // works OK
pm2 start --node-args="--inspect=7000 -r ts-node/register" app-test.ts // works but without debugger
Last example works without debugger because --node-args are passed to ts-node interpreter and finally ignored. It was working ok with [email protected]:
pm2 start --node-args="--inspect=7000" app-test.ts
TEMPORARY WORKAROUND:
After installation of typescript and ts-node modules in pm2, my global pm2 instance keep newest versions of typescript and ts-node in its node_modules subfolder:
~/.nvm/versions/node/v8.9.4/lib/node_modules/pm2/node_modules/ts-node - here is [email protected] located. To enable debugger I had to manually replace this folder with [email protected] folder installed in other place. Now debugger works, because pm2 uses 4.1.0 version by default together with newest [email protected].
Seems like you should submit a fix to pm2. The feature of using node flags via the CLI was an explicit decision and won鈥檛 be enabled in future releases.
Could it be as simple as deleting those interpreters? I noticed that the register method is used somewhere else in the code but I鈥檓 not familiar with how it works.
I don't think so it is so simple, but I'm going to try :) Thanks for your time and great project - ts-node really helps and saves a lot of development time.
Any solution yet to start newest ts-node with inspect via pm2?
I can't see in the documentation how to combine both a --preserve-symlinks arg for node, and a --project arg for ts-node.
node -r ts-node/register --preserve-symlinks --project tsconfig.server.json says unknown arg --project which makes sense.
ts-node --project tsconfig.server.json --preserve-symlinks doesn't work, probably for the same reason --inspect doesn't work.
--
Update: I was fortunate, and able to use NODE_PRESERVE_SYMLINKS=1 ts-node --project tsconfig.server.json but it is still not clear how to pass args to both ts-node and node at the same time.
@majelbstoat Unfortunately it's not possible to combine both, that's a limitation with using node.js --require. You need to use environment variables instead.
For everyone looking into this in the future:
Node supports passing almost any command line options using an environment variable called
NODE_OPTIONS: https://nodejs.org/api/cli.html#cli_node_options_options
@Nilos Both ways are possible. You can do TS_NODE_PROJECT=xxx node --require ts-node/register --extra-args index.ts or NODE_OPTIONS=xxx ts-node --project=xxx --extra-args index.ts. I documented the first approach in the README, but the second is equally valid, just uses the ts-node executable instead of the node executable. Can you share why you think one is easier than the other since they both require environment variables?
@blakeembrey I did not know about the TS_NODE_PROJECT option. Is every command line option for ts-node controllable this way?
I actually think TS_NODE_PROJECT is better as my node application spawns other node application which would inherit the NODE_OPTIONS which breaks the sub-processes.
@Nilos See https://github.com/TypeStrong/ts-node#cli-and-programmatic-options.
nodemon --config config.json
json
{ "exec": "node --inspect -r ts-node/register ./src/index.ts" }
works well
full config
`json
{
"verbose": true,
"debug": false,
"exec": "node --inspect -r ts-node/register ./src/index.ts",
"ignore": [
"mochawesome-report",
"node_modules",
"./test",
"**/*.d.ts",
"*.test.ts",
"*.spec.ts",
"fixtures/*",
"test/**/*",
"docs/*"
],
"events": {
"restart": "echo \"[Warning] Remember run npm run test b4 push to dev branch !\""
},
"watch": ["./src"],
"ext": "ts, gql",
"inspect": true
}
Thanks @agborkowski , your solution works indeed! :+1:
@agborkowski Thank you very much brother. God bless
As an alternative to environment variables or ts-node/register, you can pass options in this form:
node [node options] ./node_modules/.bin/ts-node [ts-node options] [script.ts]
e.g.
node --inspect-brk ./node_modules/.bin/ts-node --transpile-only script.ts
@agborkowski Not all heroes wear capes. +1
If you want to keep using pm2, the NODE_OPTIONS env variable works well.
Here is my configuration (after running pm2 install typescript)
apps:
- name: my-app
script: ./src/index.ts
watch:
- src
env:
NODE_OPTIONS: --inspect

Why is that?
@agborkowski @blakeembrey
@hejiaji You are probably emitting ES6 modules instead of CommonJS? I don't think it has anything to do with ts-node/register vs ts-node CLI. I'd need more information if that's not the cause.
Oh right! thanks @blakeembrey , then to more specific on my question:
i have a command like this
ts-node --typeCheck --project tsconfig.server.json --files true server/index.ts
How can i transfer to node command completely?
node -r ts-node/register server/index.ts cannot indicate the --project and --file arguments.
Figured it out!! using Environment variable to tackle this!
export TS_NODE_PROJECT=tsconfig.server.json; export TS_NODE_FILES=true && node -r ts-node/register --inspect server/index.ts
Thanks @blakeembrey
node --inspect -r ts-node/register path/to/ts
How can I also provide the --project ./tsconfig-server.json arg for ts-node ? I really need to have a different tsconfig because of react native.
Edit
Found some help here: Overriding tsconfig.json for ts-node in mocha. We need to setup a custom register for ts-node method and call it from the command line.
nodemon.json
{
"verbose": false,
"ext": "ts js json yaml",
"watch": [
"server/**/*.ts",
"server/**/*.yaml"
],
"ignore": [],
"exec": "node --inspect --require ./ts-hook.js ./server/main.ts"
}
ts-hook.js
require("ts-node").register({
project: "tsconfig-server.json",
});
@adrian-moisa export TS_NODE_PROJECT=./tsconfig-server.json ts-node path/to/ts.
@yleflour perfect solution :) thanks a lot
If you want to keep using pm2, the
NODE_OPTIONSenv variable works well.Here is my configuration (after running
pm2 install typescript)apps: - name: my-app script: ./src/index.ts watch: - src env: NODE_OPTIONS: --inspect
This helps me to configure Webstorm Debuger
node version: 12.3.1
ts-node version: 8.5.4

Most helpful comment