Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

that is undefined within list function in API.js #5928

Open
Khanon opened this issue Dec 11, 2024 · 0 comments
Open

that is undefined within list function in API.js #5928

Khanon opened this issue Dec 11, 2024 · 0 comments

Comments

@Khanon
Copy link

Khanon commented Dec 11, 2024

What's going wrong?

that is undefined within API.js list method

How could we reproduce this issue?

pm2 version: 5.4.2

ecosystem.config.json:

{
	"apps": [
		{
			"name": "system-manager-service",
			"script": "./dist/services/system-manager-service/main.js",
			"exec_mode": "cluster",
			"instances": "5",
			"watch": true,
			"env": {
			},
			"env_local": {
				"NODE_ENV": "local"
			},
			"env_dev": {
				"NODE_ENV": "dev"
			},
			"env_test": {
				"NODE_ENV": "test"
			},
			"env_www": {
				"NODE_ENV": "www"
			}
		}
	]
}

PM2 startup:

> @system-manager-service/[email protected] sms:pm2:dev
> pm2 start ./services/system-manager-service/ecosystem.config.json --env dev --no-daemon

pm2 launched in no-daemon mode (you can add DEBUG="*" env variable to get more messages)
2024-12-12T13:48:52: PM2 log: Launching in no daemon mode
2024-12-12T13:48:52: PM2 log: [PM2][WARN] Applications system-manager-service not running, starting...
2024-12-12T13:48:52: PM2 log: [Watch] Start watching system-manager-service
2024-12-12T13:48:52: PM2 log: App [system-manager-service:0] starting in -cluster mode-
2024-12-12T13:48:52: PM2 log: App [system-manager-service:0] online
2024-12-12T13:48:52: PM2 log: [Watch] Start watching system-manager-service
2024-12-12T13:48:52: PM2 log: App [system-manager-service:1] starting in -cluster mode-
2024-12-12T13:48:52: PM2 log: App [system-manager-service:1] online
2024-12-12T13:48:52: PM2 log: [Watch] Start watching system-manager-service
2024-12-12T13:48:52: PM2 log: App [system-manager-service:2] starting in -cluster mode-
2024-12-12T13:48:52: PM2 log: App [system-manager-service:2] online
2024-12-12T13:48:52: PM2 log: [Watch] Start watching system-manager-service
2024-12-12T13:48:52: PM2 log: App [system-manager-service:3] starting in -cluster mode-
2024-12-12T13:48:52: PM2 log: App [system-manager-service:3] online
2024-12-12T13:48:52: PM2 log: [Watch] Start watching system-manager-service
2024-12-12T13:48:52: PM2 log: App [system-manager-service:4] starting in -cluster mode-
2024-12-12T13:48:52: PM2 log: App [system-manager-service:4] online
2024-12-12T13:48:52: PM2 log: [PM2] App [system-manager-service] launched (5 instances)
2024-12-12T13:48:53: PM2 log: ┌────┬───────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name                      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼───────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ system-manager-service    │ default     │ 0.0.0   │ cluster │ 8968     │ 0s     │ 0    │ online    │ 7.8%     │ 51.4mb   │ Lor… │ enabled  │
│ 1  │ system-manager-service    │ default     │ 0.0.0   │ cluster │ 28520    │ 0s     │ 0    │ online    │ 7.8%     │ 51.5mb   │ Lor… │ enabled  │
│ 2  │ system-manager-service    │ default     │ 0.0.0   │ cluster │ 14564    │ 0s     │ 0    │ online    │ 1.5%     │ 51.0mb   │ Lor… │ enabled  │
│ 3  │ system-manager-service    │ default     │ 0.0.0   │ cluster │ 8788     │ 0s     │ 0    │ online    │ 9.4%     │ 47.2mb   │ Lor… │ enabled  │
│ 4  │ system-manager-service    │ default     │ 0.0.0   │ cluster │ 21372    │ 0s     │ 0    │ online    │ 6.3%     │ 44.7mb   │ Lor… │ enabled  │
└────┴───────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
2024-12-12T13:48:53: PM2 log: [--no-daemon] Continue to stream logs
2024-12-12T13:48:53: PM2 log: [--no-daemon] Exit on target PM2 exit pid=11720

I'm calling list function just like this:

import {
  list,
  ProcessDescription,
  sendDataToProcessId
} from 'pm2'

...
return new Promise((resolve, reject) => {
  list((error: any, descriptions: ProcessDescription[]) => {
  }
})
...

Error:

17:23:27 4|system-manager-service  | TypeError: Cannot read properties of undefined (reading 'Client')
17:23:27 4|system-manager-service  |     at list (C:\Projects\system-manager-service\node_modules\pm2\lib\API.js:600:10)
17:23:27 4|system-manager-service  |     at C:\Projects\system-manager-service\dist\services\system-manager-service\main.js:415:32
17:23:27 4|system-manager-service  |     at new Promise (<anonymous>)
17:23:27 4|system-manager-service  |     at PM2.initialize (C:\Projects\system-manager-service\dist\services\system-manager-service\main.js:404:16)
17:23:27 4|system-manager-service  |     at SM.initialize (C:\Projects\system-manager-service\dist\services\system-manager-service\main.js:45:25)
17:23:27 4|system-manager-service  |     at C:\Projects\system-manager-service\dist\services\system-manager-service\main.js:1365:37
17:23:27 4|system-manager-service  |     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)

API.js failing code block (line 600):

/**
   * Get list of all processes managed
   *
   * @param {Function} cb Callback
   */
  list (opts, cb) {
    var that = this;

    if (typeof(opts) == 'function') {
      cb = opts;
      opts = null;
    }

    // that is undefined
    that.Client.executeRemote('getMonitorData', {}, function(err, list) {   // << line 600
      if (err) {
        Common.printError(err);
        return cb ? cb(Common.retErr(err)) : that.exitCli(conf.ERROR_EXIT);
      }
...

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2020", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": "."
  },
  "exclude": ["node_modules", "tmp"]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant