Unitech/pm2 · error · Error
You cannot set a pm2_home and independent instance in same t
Error message
You cannot set a pm2_home and independent instance in same time
What it means
Thrown in the PM2 API constructor. The options object lets you control where PM2 stores its state (PM2_HOME): either pin it to an explicit path via pm2_home, or ask PM2 to mint a fresh unique home under /tmp via independent:true. These two are mutually exclusive — you cannot both name the home and ask for a random one in the same call.
Source
Thrown at lib/API.js:78
this.daemon_mode = typeof(opts.daemon_mode) == 'undefined' ? true : opts.daemon_mode;
this.pm2_home = conf.PM2_ROOT_PATH;
this.public_key = conf.PUBLIC_KEY || opts.public_key || null;
this.secret_key = conf.SECRET_KEY || opts.secret_key || null;
this.machine_name = conf.MACHINE_NAME || opts.machine_name || null
/**
* CWD resolution
*/
this.cwd = process.cwd();
if (opts.cwd) {
this.cwd = path.resolve(opts.cwd);
}
/**
* PM2 HOME resolution
*/
if (opts.pm2_home && opts.independent == true)
throw new Error('You cannot set a pm2_home and independent instance in same time');
if (opts.pm2_home) {
// Override default conf file
this.pm2_home = opts.pm2_home;
conf = Object.assign(conf, path_structure(this.pm2_home));
}
else if (opts.independent == true && conf.IS_WINDOWS === false) {
// Create an unique pm2 instance
const crypto = require('crypto');
var random_file = crypto.randomBytes(8).toString('hex');
this.pm2_home = path.join('/tmp', random_file);
// If we dont explicitly tell to have a daemon
// It will go as in proc
if (typeof(opts.daemon_mode) == 'undefined')
this.daemon_mode = false;
conf = Object.assign(conf, path_structure(this.pm2_home));
}View on GitHub (pinned to 31adee8048)
Solutions
- Remove one of the two keys — choose a single PM2 home strategy.
- If you want a dedicated isolated instance with a random home, drop pm2_home and keep independent:true.
- If you want a fixed, known location, drop independent and keep pm2_home.
Example fix
// before
new PM2({ pm2_home: '/var/pm2', independent: true });
// after
new PM2({ pm2_home: '/var/pm2' }); Defensive patterns
Strategy: validation
Validate before calling
function createPm2(opts) {
if (opts && opts.pm2_home && opts.independent === true) {
throw new TypeError('pm2_home and independent are mutually exclusive; pass exactly one');
}
return new (require('pm2'))(opts);
} Type guard
function isValidPm2Opts(opts) {
return !(opts && opts.pm2_home && opts.independent === true);
} Prevention
- Treat independent:true as an alternative to pm2_home, never an addition.
- Never merge unrelated config presets without deduping mutually-exclusive keys.
- Assert the invariant in your own factory wrapping new PM2(opts).
When it happens
Trigger: Instantiating `new PM2({ pm2_home: '/some/path', independent: true })` (or pm2.connect with the same opts) — both keys present at once.
Common situations: Merging two config presets where one sets pm2_home and another sets independent:true; copy-pasting options from different examples; test harnesses that force independent mode combined with a fixed home.
Related errors
AI-assisted analysis of Unitech/pm2@31adee8048 (2026-08-13).
Data as JSON: /api/errors/37b7c556dae94cc5.
Report an issue: GitHub.