javascript - How can I debug a NodeJS application in IntelliJ Idea? - Stack Overflow

I have a NodeJS project with a package.json file that contains following lines:"scripts": {[.

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 mand 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).

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: 
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?

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 mand 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).

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/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?

Share Improve this question asked Apr 22, 2020 at 15:05 Glory to RussiaGlory to Russia 18.8k60 gold badges200 silver badges344 bronze badges 5
  • Do you have cross-env installed globally for the Node version IntelliJ is using? – jonrsharpe Commented Apr 22, 2020 at 15:08
  • @jonrsharpe No (at least I don't remember installing it globally). – Glory to Russia Commented Apr 22, 2020 at 15:09
  • Then it shouldn't be particularly surprising that doesn't work! Why not use the NPM task runner to use the existing start:dev? – jonrsharpe Commented Apr 22, 2020 at 15:10
  • @jonrsharpe How exactly can I do it so that the breakpoints work in Idea? – Glory to Russia Commented Apr 22, 2020 at 15:10
  • I didn't have to do anything special, just add an npm configuration, select the script I wanted and click debug. – jonrsharpe Commented Apr 22, 2020 at 15:17
Add a ment  | 

1 Answer 1

Reset to default 9

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

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

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744187906a4562294.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信