{"record":{"id":"48d78dea87428cdc","repo":"Unitech/pm2","slug":"attribute-name-should-be-present","errorCode":null,"errorMessage":"Attribute name should be present","messagePattern":"Attribute name should be present","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/API/Modules/TAR.js","lineNumber":306,"sourceCode":"  tar.on('close', function (code) {\n    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 = {","sourceCodeStart":288,"sourceCodeEnd":324,"githubUrl":"https://github.com/Unitech/pm2/blob/31adee8048dbbc1ee36a7df7cdbcaca2559708df/lib/API/Modules/TAR.js#L288-L324","documentation":"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.","triggerScenarios":"Running `pm2 publish` in a directory whose package.json has no \"name\" field.","commonSituations":"A new/scaffolded package.json missing name; a private app accidentally published as a PM2 module; running publish from the wrong directory.","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."],"exampleFix":"// before\n{ \"version\": \"1.0.0\" }\n// after\n{ \"name\": \"my-pm2-module\", \"version\": \"1.0.0\" }","handlingStrategy":"validation","validationCode":"const pkg = require('./package.json');\n['name', 'version'].forEach((k) => {\n  if (!pkg[k]) throw new Error(`package.json missing required field \"${k}\"`);\n});","typeGuard":"function hasModuleName(pkg) {\n  return typeof pkg === 'object' && typeof pkg.name === 'string' && pkg.name.length > 0;\n}","tryCatchPattern":null,"preventionTips":["Run a package.json field linter before publishing modules.","Keep name lowercase-hyphenated per npm naming rules."],"tags":["publish","package-json","modules"],"backgroundTag":null,"analyzedSha":"31adee8048dbbc1ee36a7df7cdbcaca2559708df","analyzedAt":"2026-08-13T03:49:51.765Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}