PM2 fails to start a server ecosystem from a .JSON file. As an aside, I'm also unable to generate the ecosystem file using generate OR ecosystem.
I'm running on node 5.9.1 and PM2 1.1.3 (installed today). I've looked around forums and through GIT but didn't find my exact issue. My .JSON is attached.
LabMan.zip
The error I'm receiving is :
`C:UsersMYUSERAppDataRoamingnpmnode_modulespm2libCLI.js:461
Common.printOut(cst.PREFIX_MSG + 'App [%s] launched (%d instances)', data[0].pm2_env.name, data.length);
^
TypeError: Cannot read property 'pm2_env' of undefined
at C:UsersMYUSERAppDataRoamingnpmnode_modulespm2libCLI.js:461:85
at C:UsersMYUSERAppDataRoamingnpmnode_modulespm2node_modulespm2-axon-rpclibclient.js:45:10
at Parser.
at emitOne (events.js:90:13)
at Parser.emit (events.js:182:7)
at Parser._write (C:UsersMYUSERAppDataRoamingnpmnode_modulespm2node_modulesamplibstream.js:91:
at doWrite (_stream_writable.js:301:12)
at writeOrBuffer (_stream_writable.js:287:5)
at Parser.Writable.write (_stream_writable.js:215:11)
at Socket.ondata (_stream_readable.js:536:20)`
I have tried uninstalling pm2 and reinstalling to no avail. There are two optional dependencies which say they've failed to install.
npm WARN optional Skipping failed optional dependency /pm2/ikt:
npm WARN not found: git
npm WARN optional Skipping failed optional dependency /chokidar/fsevents:
npm WARN notsup Not compatible with your operating system or architecture: [email protected]
Any help would be very appreciated!
Oh, one last thing... Since the generate/ecosystem commands fail for me I took an example of the .JSON from here : https://keymetrics.io/2014/06/25/ecosystem-json-deploy-and-iterate-faster/
There's definitely something that should give a more readable error instead of this.
Optional dependencies are not an issue.
Can you check your paths in the json (cwd, script)? You can also try to remove cwd and only give the full script path.
Thanks for the ecosystem examples. I'll test it out without the cwd to see if that helps, and triple check the paths ASAP.
(Got pulled onto another project for a few days.)
I changed the JSON to the following...
{
"apps" : [
{
// Core LabMan application
"name" : "LabMan_CORE",
"script" : "Core.js",
"watch" : false,
"error_file" : "./logs/CoreErr.log",
"out_file" : "./logs/Status.log",
"env": { "COMMON_ENV_VAR": "true" },
"env_production": { "NODE_ENV": "production" }
}
,{
"name" : "LabMan_QQ",
"script" : "lm_services/quickQuery.js",
"watch" : false
}
]
}
And found that it works fine. after some comment/comment out I found the issue... For some reason I cannot add error_file and out_file to multiple app definitions. Is this by design? If so, then I'll need to put in a feature request here shortly. :)
Also, it'd be nice to have an error in form of "You have an error in the JSON file you're trying to launch from" or something. But in the end, it looks like there was a problem with my implementation.
I'm honestly not sure why I wasn't able to get it working when I commented out one of the two apps the other day, but it is what it is.
Thank you for your responsiveness and suggestion to take out the cwd. Doing so prompted me to look into whether it was truly needed or not.... Turns out it's really not in my case. :)
You should be able to add out_file and err_file to both processes declaration.
Also, it'd be nice to have an error in form of "You have an error in the JSON file you're trying to launch from" or something. But in the end, it looks like there was a problem with my implementation.
+1
I thought I should be able to, but when I try it dies with the error above.
Anyway, I'll go and close this one out, since I've at least got the launch going now.
Thanks again.
I'll reopen as we need to check this, and also because the error message should state that the json isn't valid.
Sounds good, let me know if you need any more details from my instance.
fixed in development PM2 V2
@ScriptPup I have the same issue as you. When I start pm2 json from root everything works as expected. Not sure why that is not a case when I try from normal user. So, I also removed error_file and out_file from two out of three definitions.
Do you have some solution for this since I would like to have error_file and out_file for all definitions?
Thanks
TLDR Useful information for pm2-docker users googling this cryptic message (as I have been doing on and off all week)
TypeError: Cannot read property 'pm2_env' of undefined
This occurs because either the parsing of the process file itself failed, or contents of a process file is somehow incorrect, or a configured file cannot be read/written to
error_log or output_log directives point to locations docker cannot write toscript not found)error_log or output_log options refer to locations that docker cannot write to.pm2-docker start path/to/process.yml versus pm2-docker path/to/process.yml) (the documentation isn't clear on this but failures have been noted)Just want to add another reason to @mschnee list (thanks a lot btw!). We use serve library to bring up our app, and serve was not part of package.json, after adding it the problem was gone.
Most helpful comment
TLDR Useful information for
pm2-dockerusers googling this cryptic message (as I have been doing on and off all week)This occurs because either the parsing of the process file itself failed, or contents of a process file is somehow incorrect, or a configured file cannot be read/written to
error_logoroutput_logdirectives point to locations docker cannot write toscript not found)error_logoroutput_logoptions refer to locations that docker cannot write to.pm2-docker start path/to/process.ymlversuspm2-docker path/to/process.yml) (the documentation isn't clear on this but failures have been noted)