最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How Node.js console application from "node_modules" stop on "debugger" statement when invoke

programmeradmin6浏览0评论

The Simplest Explanation & Question

Assume that we are Webpack developers and debugging the Webpack (well, nothing will change for this question if substitute Webpack with Gulp or Vite). We have done npm install webpack to some project. When run the webpack build via console, maybe we will use some options, for example, npx webpack build --config ./webpack.config.js --stats verbose. There are some debugger statements in the source code of Webpack version which we have installed. How to make Webpack stop when debug statement will reached?

My case

My utility is similar to Webpack. Well, it uses the Webpack, and also Gulp as dependencies. As pure Webpack and Gulp, my utility is intended to be executed in other projects so it is completely useless to run it without external project.

As Webpack and Gulp, once installed to another project, it is being called by CLI:

myutil build --mode production

myutil command has been declared in the package.json of my utility:

{
  // ...
  "bin": {
    "myutil": "Executable"
  },
}

How it generally being done?

Well, it has been clearly answered in another topics.

To debug a Node.js application, one can use the debugging built-in method:

(1) Insert debugger; statement where you want to insert a break point (2) Run the file with command $ node inspect (3) Use a key for example, c to continue to next break point

Alternatively, node --inspect-brk Test.js.

Why it is not suited with my case?

Because the application is being launched via CLI like myutil build --mode production. As far as I can assume, the Node.js, basing on "bin": { "myutil": "Executable" } declaration in package.json of dependency executing the Executable, the JS file wiht #!/usr/bin/env node shebang line.

As I previously said, there is completely useless to execute node inspect Executable because my utility is not intended to be executed inside own package and will fail with error.

Additionally, my utility has some required parameter and will throw error is detect some unexpected parameters.

What I am debugging?

The RangeError: Maximum call stack size exceeded error. Additionally, if to try console.log, it will instantly overflow the terminal and some initial outputs will be truncated. I need the stop by debugger very much.

The Simplest Explanation & Question

Assume that we are Webpack developers and debugging the Webpack (well, nothing will change for this question if substitute Webpack with Gulp or Vite). We have done npm install webpack to some project. When run the webpack build via console, maybe we will use some options, for example, npx webpack build --config ./webpack.config.js --stats verbose. There are some debugger statements in the source code of Webpack version which we have installed. How to make Webpack stop when debug statement will reached?

My case

My utility is similar to Webpack. Well, it uses the Webpack, and also Gulp as dependencies. As pure Webpack and Gulp, my utility is intended to be executed in other projects so it is completely useless to run it without external project.

As Webpack and Gulp, once installed to another project, it is being called by CLI:

myutil build --mode production

myutil command has been declared in the package.json of my utility:

{
  // ...
  "bin": {
    "myutil": "Executable"
  },
}

How it generally being done?

Well, it has been clearly answered in another topics.

To debug a Node.js application, one can use the debugging built-in method:

(1) Insert debugger; statement where you want to insert a break point (2) Run the file with command $ node inspect (3) Use a key for example, c to continue to next break point

Alternatively, node --inspect-brk Test.js.

Why it is not suited with my case?

Because the application is being launched via CLI like myutil build --mode production. As far as I can assume, the Node.js, basing on "bin": { "myutil": "Executable" } declaration in package.json of dependency executing the Executable, the JS file wiht #!/usr/bin/env node shebang line.

As I previously said, there is completely useless to execute node inspect Executable because my utility is not intended to be executed inside own package and will fail with error.

Additionally, my utility has some required parameter and will throw error is detect some unexpected parameters.

What I am debugging?

The RangeError: Maximum call stack size exceeded error. Additionally, if to try console.log, it will instantly overflow the terminal and some initial outputs will be truncated. I need the stop by debugger very much.

Share Improve this question asked Mar 20 at 7:59 Takeshi Tokugawa YDTakeshi Tokugawa YD 1,0308 gold badges66 silver badges178 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

If Executable imports the entry point which executing the application (for example index.js), than the debugging is possible by:

node --inspect-brk node_modules/myutil/index.js [options]

Any options of myutil could be passed at [opiton] placeholder.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论