{"record":{"id":"4a616b9acc3aa806","repo":"Unitech/pm2","slug":"could-not-load-the-script","errorCode":null,"errorMessage":"Could not _load() the script","messagePattern":"Could not _load\\(\\) the script","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"lib/ProcessContainerFork.js","lineNumber":35,"sourceCode":"\nif (process.connected &&\n    process.send &&\n    process.versions &&\n    process.versions.node)\n  process.send({\n    'node_version': process.versions.node\n  });\n\n// Require the real application\nif (process.env.pm_exec_path) {\n  if (ProcessUtils.isESModule(process.env.pm_exec_path) === true) {\n    import(url.pathToFileURL(process.env.pm_exec_path));\n  }\n  else\n    require('module')._load(process.env.pm_exec_path, null, true);\n}\nelse\n  throw new Error('Could not _load() the script');\n\n// Change some values to make node think that the user's application\n// was started directly such as `node app.js`\nprocess.mainModule = process.mainModule || {};\nprocess.mainModule.loaded = false;\nrequire.main = process.mainModule;\n","sourceCodeStart":17,"sourceCodeEnd":42,"githubUrl":"https://github.com/Unitech/pm2/blob/31adee8048dbbc1ee36a7df7cdbcaca2559708df/lib/ProcessContainerFork.js#L17-L42","documentation":"ProcessContainerFork.js is the wrapper process PM2 forks for each app instance. It reads process.env.pm_exec_path and loads the user's script via import() (ESM) or module._load() (CJS). If pm_exec_path is missing or falsy there is no script to run, so the forked wrapper throws.","triggerScenarios":"PM2 forks a worker but the environment was not seeded with pm_exec_path — typically an internally inconsistent state: corrupted dump file, a process resurrected from an older PM2 version, or programmatic launch with an incomplete env.","commonSituations":"Resurrecting a dump.json saved by an incompatible/older PM2; manually constructed process envs; an app entry whose path failed to resolve before fork.","solutions":["Delete and re-add the affected app: `pm2 delete <app>` then `pm2 start <entry>`.","Clear and regenerate the dump: stop everything, `pm2 save` once after a clean start.","Ensure your ecosystem/script path resolves to an existing file before starting."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"if (!process.env.pm_exec_path) {\n  console.error('pm_exec_path missing; refusing to fork a wrapper with no script');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":"try {\n  pm2.start(app, cb);\n} catch (e) {\n  if (/Could not _load\\(\\) the script/.test(e.message)) {\n    pm2.delete(app.name, () => pm2.start(app, cb)); // reset and re-add\n  } else { throw e; }\n}","preventionTips":["After upgrading PM2, regenerate the dump (pm2 save) to avoid resurrecting stale envs.","Delete and re-add apps whose entry paths have changed.","Treat a missing pm_exec_path as a signal of dump corruption — start clean."],"tags":["process","fork","internal"],"backgroundTag":null,"analyzedSha":"31adee8048dbbc1ee36a7df7cdbcaca2559708df","analyzedAt":"2026-08-13T03:49:51.765Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}