{"record":{"id":"62131afc51337cac","repo":"Unitech/pm2","slug":"module-package-json-not-defined","errorCode":null,"errorMessage":"module package.json not defined","messagePattern":"module package\\.json not defined","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/API/Modules/NPM.js","lineNumber":346,"sourceCode":"  if (!app_name) throw new Error('No app_name defined');\n\n  var module_conf = Configuration.getAllSync();\n\n  var additional_env = {};\n\n  if (!module_conf[app_name]) {\n    additional_env = {};\n    additional_env[app_name] = {};\n  }\n  else {\n    additional_env = Common.clone(module_conf[app_name]);\n    additional_env[app_name] = JSON.stringify(module_conf[app_name]);\n  }\n  return additional_env;\n}\n\nfunction StartModule(CLI, opts, cb) {\n  if (!opts.cmd && !opts.package) throw new Error('module package.json not defined');\n  if (!opts.development_mode) opts.development_mode = false;\n\n  var package_json = require(opts.cmd || opts.package);\n\n  /**\n   * Script file detection\n   * 1- *apps* field (default pm2 json configuration)\n   * 2- *bin* field\n   * 3- *main* field\n   */\n  if (!package_json.apps && !package_json.pm2) {\n    package_json.apps = {};\n\n    if (package_json.bin) {\n      var bin = Object.keys(package_json.bin)[0];\n      package_json.apps.script = package_json.bin[bin];\n    }\n    else if (package_json.main) {","sourceCodeStart":328,"sourceCodeEnd":364,"githubUrl":"https://github.com/Unitech/pm2/blob/31adee8048dbbc1ee36a7df7cdbcaca2559708df/lib/API/Modules/NPM.js#L328-L364","documentation":"StartModule loads and launches a PM2 module from its package.json. It needs either opts.cmd or opts.package (both are alternate keys pointing at the package.json path) so it can require() it. With neither set there is no file to load, so it throws immediately.","triggerScenarios":"Calling the module-start flow programmatically with an opts object that has neither cmd nor package (e.g. only development_mode, safe, or other metadata keys).","commonSituations":"Programmatic module start with the wrong options shape; passing a directory or tarball but forgetting to set the package.json path on opts.","solutions":["Set opts.cmd (or opts.package) to the absolute path of the module's package.json.","If using the CLI, ensure the module name/URL resolves to a directory containing a package.json."],"exampleFix":"// before\nStartModule(CLI, { development_mode: true }, cb);\n// after\nStartModule(CLI, { cmd: '/abs/path/to/module/package.json', development_mode: true }, cb);","handlingStrategy":"validation","validationCode":"if (!opts.cmd && !opts.package) {\n  return cb(new Error('Pass opts.cmd or opts.package pointing to the module package.json'));\n}","typeGuard":"function hasPackageRef(opts) {\n  return Boolean(opts && (opts.cmd || opts.package));\n}","tryCatchPattern":null,"preventionTips":["Always normalize module-start options to include a resolved package.json path before delegating to StartModule.","Resolve the path to absolute and fs.existsSync-check it before calling."],"tags":["modules","package-json","precondition"],"backgroundTag":null,"analyzedSha":"31adee8048dbbc1ee36a7df7cdbcaca2559708df","analyzedAt":"2026-08-13T03:49:51.765Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}