clinicjs / node-clinic

Clinic.js diagnoses your Node.js performance issues
https://clinicjs.org
MIT License
5.67k stars 125 forks source link

Usage with Electron #354

Open publicvirtualvoid opened 2 years ago

publicvirtualvoid commented 2 years ago

Is it possible to use clinic.js with Electron? I love the way this works but am dealing with some performance bottlenecks in an Electron application.

RafaelGSS commented 2 years ago

Honestly, I haven't used it in an electron app. But, certainly is a doable feature.

Is it throwing an error?

VikramTiwari commented 2 years ago

Hey folks! Any idea how you would use this with electron app.

My dev script in package.json is NODE_ENV=development electron ./dist/main.cjs and when I update it with clinic doctor -- NODE_ENV=development electron ./dist/main.cjs it throws following error:

Clinic.js must be called with a `node` command line: `clinic doctor -- node script.js`

Ideas?

RafaelGSS commented 2 years ago

Try: clinic doctor -- node ./node_modules/.bin/electron ./dist/main.cjs

VikramTiwari commented 2 years ago

Thank you @RafaelGSS! This was helpful to get it started.

However, on my side, I can get it started and it opens up the dashboard page. However, the process is crashing on the CLI. Here are the logs:

$ NODE_ENV=development clinic doctor -- node ./node_modules/.bin/electron ./dist/main.cjs
To generate the report press: Ctrl + C
node:internal/modules/cjs/loader:943
  throw err;
  ^

Error: Cannot find module 'no-cluster.js'
Require stack:
- internal/preload
    at Module._resolveFilename (node:internal/modules/cjs/loader:940:15)
    at Module._load (node:internal/modules/cjs/loader:785:27)
    at Module.require (node:internal/modules/cjs/loader:1012:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1296:12)
    at loadPreloadModules (node:internal/bootstrap/pre_execution:479:5)
    at prepareMainThreadExecution (node:internal/bootstrap/pre_execution:77:3)
    at node:internal/main/run_main_module:7:1 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}
process exited with exit code 1
Analysing data
Generated HTML file is file:///Users/vikramtiwari/Documents/code/app/.clinic/56981.clinic-doctor.html
RafaelGSS commented 2 years ago

Could you create a reproducible code? Reference: https://stackoverflow.com/help/minimal-reproducible-example.

publicvirtualvoid commented 1 year ago

Same here, also tried with electron-quick-start:

To generate the report press: Ctrl + C

node:internal/modules/cjs/loader:1085
  throw err;
  ^

Error: Cannot find module 'no-cluster.js'
Require stack:
- internal/preload
    at Module._resolveFilename (node:internal/modules/cjs/loader:1082:15)
    at Module._load (node:internal/modules/cjs/loader:927:27)
    at internalRequire (node:internal/modules/cjs/loader:181:19)
    at Module._preloadModules (node:internal/modules/cjs/loader:1447:5)
    at loadPreloadModules (node:internal/process/pre_execution:613:5)
    at setupUserModules (node:internal/process/pre_execution:118:3)
    at prepareExecution (node:internal/process/pre_execution:109:5)
    at prepareMainThreadExecution (node:internal/process/pre_execution:37:3)
    at node:internal/main/run_main_module:10:1 {
  code: 'MODULE_NOT_FOUND',
  requireStack: [ 'internal/preload' ]
}

Node.js v18.15.0
process exited with exit code 1
Analysing data
Generated HTML file is file:/// 

Repro here, have linked to only changes made from the quickstart project: https://github.com/publicvirtualvoid/electron-clinic-repro/commit/f31d49432d80e61b74756632ffa354e70afe75b2