{"record":{"id":"9bc91141796878fc","repo":"Unitech/pm2","slug":"attribute-version-should-be-present","errorCode":null,"errorMessage":"Attribute version should be present","messagePattern":"Attribute version should be present","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/API/Modules/TAR.js","lineNumber":307,"sourceCode":"    cb(code == 0 ? null : code, {\n      package_name: pkg_name,\n      path: target_fullpath\n    })\n  })\n}\n\nfunction publish(PM2, folder, cb) {\n  var target_folder = folder ? path.resolve(folder) : process.cwd()\n\n  try {\n    var pkg = JSON.parse(fs.readFileSync(path.join(target_folder, 'package.json')).toString())\n  } catch(e) {\n    Common.errMod(`${process.cwd()} module does not contain any package.json`)\n    process.exit(1)\n  }\n\n  if (!pkg.name) throw new Error('Attribute name should be present')\n  if (!pkg.version) throw new Error('Attribute version should be present')\n  if (!pkg.pm2 && !pkg.apps) throw new Error('Attribute apps should be present')\n\n  var current_path = target_folder\n  var module_name = path.basename(current_path)\n  var target_path = os.tmpdir()\n\n  Common.logMod(`Starting publishing procedure for ${module_name}@${pkg.version}`)\n\n  packager(current_path, target_path, (err, res) => {\n    if (err) {\n      Common.errMod('Can\\'t package, exiting')\n      process.exit(1)\n    }\n\n    Common.logMod(`Package [${pkg.name}] created in path ${res.path}`)\n\n    var data = {\n      module_data: {","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/Unitech/pm2/blob/31adee8048dbbc1ee36a7df7cdbcaca2559708df/lib/API/Modules/TAR.js#L289-L325","documentation":"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.","triggerScenarios":"Running `pm2 publish` where package.json has a name but no \"version\" field.","commonSituations":"New package.json with name set but version omitted; version field accidentally removed.","solutions":["Add a semver \"version\" field to package.json (e.g. \"1.0.0\").","Bump with `npm version patch|minor|major` before publishing."],"exampleFix":"// before\n{ \"name\": \"x\" }\n// after\n{ \"name\": \"x\", \"version\": \"1.0.0\" }","handlingStrategy":"validation","validationCode":"const pkg = require('./package.json');\nif (!pkg.version || !/^[0-9]+\\.[0-9]+\\.[0-9]+/.test(pkg.version)) {\n  throw new Error('package.json requires a valid semver \"version\" field');\n}","typeGuard":"const hasSemver = (pkg) => typeof pkg.version === 'string' && /^[0-9]+\\.[0-9]+\\.[0-9]+/.test(pkg.version);","tryCatchPattern":null,"preventionTips":["Use `npm version patch|minor|major` to keep version valid and bumped.","Validate required package.json fields in a pre-publish CI step."],"tags":["publish","package-json","semver"],"backgroundTag":null,"analyzedSha":"31adee8048dbbc1ee36a7df7cdbcaca2559708df","analyzedAt":"2026-08-13T03:49:51.765Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}