Error connecting to socketio in production

realtime isnt wokring on my production instance.

node version is 20.16
ERPNext: v14.x.x-develop () (develop)

Frappe Framework: v15.x.x-develop () (develop)

this is my node-socketio.error.log

internal/modules/cjs/loader.js:818
throw err;
^

Error: Cannot find module ‘node:http’
Require stack:

  • /home/areeb/frappe-bench/apps/frappe/realtime/index.js
  • /home/areeb/frappe-bench/apps/frappe/socketio.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:815:15)
    at Function.Module._load (internal/modules/cjs/loader.js:667:27)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:85:18)
    at Object. (/home/areeb/frappe-bench/apps/frappe/realtime/index.js:2:14)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions…js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19) {
    code: ‘MODULE_NOT_FOUND’,
    requireStack: [
    ‘/home/areeb/frappe-bench/apps/frappe/realtime/index.js’,
    ‘/home/areeb/frappe-bench/apps/frappe/socketio.js’
    ]
    }

try bench build --apps frappe

sorry that doesnt seem to work

I think the issue might be with the Node.js version. Try running nvm use --lts to switch to the latest LTS version.

my node version is 20.16

i did this but still getting the same

I found node command in supervisor configuration is wrong,
bench launch socketio.js with system node and not user node

For example ubuntu 22 ships with node v12 at usr/bin/node, but in supervisor bench use the system one instead the one that you installed as v18 or v20.
command=/usr/bin/node /home/ubuntu/frappe-15/apps/frappe/socketio.js

I fixed by editing supervisor config

### FIX Node Path in Supervisor ###
which node
sudo nano /etc/supervisor/conf.d/frappe-15.conf
  
  [program:frappe-15-node-socketio]
  #command=/usr/bin/node /home/ubuntu/frappe-15/apps/frappe/socketio.js
  command=/home/ubuntu/.nvm/versions/node/v18.20.5/bin/node /home/ubuntu/frappe-15/apps/frappe/socketio.js