keymetrics / pm2-io-apm

PM2.io APM for Node.JS
Apache License 2.0
147 stars 39 forks source link

Module configuration is not loaded #260

Open Jswk1 opened 5 years ago

Jswk1 commented 5 years ago

Hello. I'm having problems with module development using latest @pm2/io version 4.2.6. Previously I've been using the deprecated Pmx module https://github.com/keymetrics/pmx and it worked correctly with the same code.

This is my startup code for module:

import * as Pmx from "@pm2/io";

Pmx.initModule({
    type: "generic",
    el: {
        probes: false,
        actions: true
    },
    block: {
        actions: true,
        cpu: true,
        mem: true
    }
}, (err, config) => {
//...
});

The config object in Pmx.initModule callback is some default configuration and it doesn't contain my settings neither from package.json nor module_conf.json file:

{ widget:
{ type: 'generic',
logo: 'https://app.keymetrics.io/img/logo/keymetrics-300.png',
theme: [ '#111111', '#1B2228', '#807C7C', '#807C7C' ] },
type: 'generic',
el: { probes: false, actions: true },
block: { actions: true, cpu: true, mem: true },
isModule: true,
module_conf: {},
apm: { type: 'node', version: '4.2.6' },
module_version: '3.5.1',
module_name: 'pm2',
description: 'Production process manager for Node.JS applications with a built-in load balancer.' }

I have the config section in my package.json of my module package and the same config in module_conf.json file in the section of my module name.

Is there anything else that should be done to load configuration?

Jswk1 commented 4 years ago

Even the pm2-logrotate still uses the deprecated Pmx module where it works correctly and it also works correctly in my case.

From my brief debugging I was able to find out that the config is loaded correctly in the Pmx.init method but not Pmx.initModule. The config is loaded in Configuration.init and sent to PM2 but the module process is never refreshed with these settings for some reason.

Huzzle commented 2 years ago

Configuration.findPackageJson returns wrong path to package.json file. It tries to resolve a path based on require.main.filename and it contains path to ProcessContainerFork.js file and as a result @pm2/io parses package.json file of pm2 package instead of a module one.

ClikeX commented 1 year ago

Is there any update on this issue?

I think most if not all of the modules [listed on the website}(https://pm2.io/docs/plus/guide/modules/) still use the deprecated pmx library because of this issue.