Glory to Russia
Glory to Russia

Reputation: 18760

How can I debug a NodeJS application in IntelliJ Idea?

I have a NodeJS project with a package.json file that contains following lines:

"scripts": {
  [...]
  "start:dev": "cross-env NODE_ENV=local supervisor --watch src -- -r '@babel/register' src/server/index.js",
  [...]
}

I can start the program in the command line using npm run start:dev.

Now I want to debug some of the code. For this purpose I created a NodeJS Run configuration in Idea with the following parameters (pasted cross-env NODE_ENV=local supervisor --watch src -- -r '@babel/register' src/server/index.js into Node Parameters).

Run/Debug Configurations dialog

When I run it, I get the following error:

/usr/bin/node cross-env NODE_ENV=local supervisor --watch src -- -r '@babel/register' src/server/index.js
Debugger listening on ws://127.0.0.1:43392/5a2c1e8e-a508-4578-8eb0-2bc4f4a63b30
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
internal/modules/cjs/loader.js:775
    throw err;
    ^

Error: Cannot find module '/home/JIT/d.pisarenko/Development/Repositories/git/myproject/cross-env'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:772:15)
    at Function.Module._load (internal/modules/cjs/loader.js:677:27)
    at Function.Module.runMain (internal/modules/cjs/loader.js:999:10)
    at internal/main/run_main_module.js:17:11 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Process finished with exit code 1

What do I need to change in order to be able to start the application in Idea and debug it?

Upvotes: -1

Views: 3887

Answers (1)

Glory to Russia
Glory to Russia

Reputation: 18760

Found the answer. You need to click the green arrow next to the script definition (next to the line numbers 8 and 9):

Screenshot

There you can select whether to run or debug the script.

Upvotes: 9

Related Questions