Unitech/pm2 · error · Error
Attribute name should be present
Error message
Attribute name should be present
What it means
pm2 publish packages the current directory (or a target folder) as a PM2 module. After reading package.json it requires the "name" field — the module's publish identity used for tar packaging and module registration. A package.json without name has no module identity, so publish aborts.
Source
Thrown at lib/API/Modules/TAR.js:306
tar.on('close', function (code) {
cb(code == 0 ? null : code, {
package_name: pkg_name,
path: target_fullpath
})
})
}
function publish(PM2, folder, cb) {
var target_folder = folder ? path.resolve(folder) : process.cwd()
try {
var pkg = JSON.parse(fs.readFileSync(path.join(target_folder, 'package.json')).toString())
} catch(e) {
Common.errMod(`${process.cwd()} module does not contain any package.json`)
process.exit(1)
}
if (!pkg.name) throw new Error('Attribute name should be present')
if (!pkg.version) throw new Error('Attribute version should be present')
if (!pkg.pm2 && !pkg.apps) throw new Error('Attribute apps should be present')
var current_path = target_folder
var module_name = path.basename(current_path)
var target_path = os.tmpdir()
Common.logMod(`Starting publishing procedure for ${module_name}@${pkg.version}`)
packager(current_path, target_path, (err, res) => {
if (err) {
Common.errMod('Can\'t package, exiting')
process.exit(1)
}
Common.logMod(`Package [${pkg.name}] created in path ${res.path}`)
var data = {View on GitHub (pinned to 31adee8048)
Solutions
- Add a valid "name" field to package.json (lowercase, hyphenated, no spaces).
- Make sure you run pm2 publish from the directory that contains the intended package.json.
Example fix
// before
{ "version": "1.0.0" }
// after
{ "name": "my-pm2-module", "version": "1.0.0" } Defensive patterns
Strategy: validation
Validate before calling
const pkg = require('./package.json');
['name', 'version'].forEach((k) => {
if (!pkg[k]) throw new Error(`package.json missing required field "${k}"`);
}); Type guard
function hasModuleName(pkg) {
return typeof pkg === 'object' && typeof pkg.name === 'string' && pkg.name.length > 0;
} Prevention
- Run a package.json field linter before publishing modules.
- Keep name lowercase-hyphenated per npm naming rules.
When it happens
Trigger: Running `pm2 publish` in a directory whose package.json has no "name" field.
Common situations: A new/scaffolded package.json missing name; a private app accidentally published as a PM2 module; running publish from the wrong directory.
Related errors
- module package.json not defined
- Attribute version should be present
- No app_name defined
- Cannot find package.json
AI-assisted analysis of Unitech/pm2@31adee8048 (2026-08-13).
Data as JSON: /api/errors/48d78dea87428cdc.
Report an issue: GitHub.