Unitech/pm2 · error · Error

Attribute version should be present

Error message

Attribute version should be present

What it means

Companion to the name check in TAR.publish: the publishing procedure also requires a "version" field (semver) so it can tag and register the module release. package.json without version fails this check.

Source

Thrown at lib/API/Modules/TAR.js:307

    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 = {
      module_data: {

View on GitHub (pinned to 31adee8048)

Solutions

  1. Add a semver "version" field to package.json (e.g. "1.0.0").
  2. Bump with `npm version patch|minor|major` before publishing.

Example fix

// before
{ "name": "x" }
// after
{ "name": "x", "version": "1.0.0" }
Defensive patterns

Strategy: validation

Validate before calling

const pkg = require('./package.json');
if (!pkg.version || !/^[0-9]+\.[0-9]+\.[0-9]+/.test(pkg.version)) {
  throw new Error('package.json requires a valid semver "version" field');
}

Type guard

const hasSemver = (pkg) => typeof pkg.version === 'string' && /^[0-9]+\.[0-9]+\.[0-9]+/.test(pkg.version);

Prevention

When it happens

Trigger: Running `pm2 publish` where package.json has a name but no "version" field.

Common situations: New package.json with name set but version omitted; version field accidentally removed.

Related errors


AI-assisted analysis of Unitech/pm2@31adee8048 (2026-08-13). Data as JSON: /api/errors/9bc91141796878fc. Report an issue: GitHub.