简体   繁体   中英

How can Heroku crash from a package.json version number?

I'm running a Discord bot on Heroku, using GitHub. At some point, Heroku suddenly crashed while starting my app. The build went fine, but it couldn't find any of my dependencies on startup (crashed on the first one but later figured out it didn't have all of them). As installing my dependencies using Heroku's console ( heroku run npm install discord.js etc.)and then starting the app worked, it became clear that Heroku wasn't installing the dependencies.

While changing one file at a time and then deploying again I finally found the culprit: Changing my version number in package.json to 3.7. 3.6.4 was fine (previous version), 3.7 crashed it, Reverting to 3.6.4 (just the number!) or skipping to 3.7.1 fixed it. Now I guess my question is, how can having a different version number in package.json crash the app when it's requiring its modules?

Just to show it's really just the version number, here's my package.json:

{
  "name": "myapp",
  "version": "3.7",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "author",
  "license": "ISC",
  "dependencies": {
    "discord.js": "^11.5.1",
    "find": "^0.3.0",
    "firebase-admin": "^8.9.2",
    "fs": "0.0.1-security",
    "python-shell": "^1.0.8"
  }
}

I just can't wrap my head around it. And right, I know this isn't the cleanest package.json but it's worked before from version 0 to 3.6.4 so I figured it not having scripts/engines etc. wouldn't be the issue... Maybe anyone here has any idea what was the issue?

Just stumbled upon the answer myself. The version number uses semver syntax which needs three sections, separated by a dot. Running it locally Node doesn't really seem to care about this syntax, but apparently Heroku does. Heroku probably doesn't use the package.json file when the syntax is incorrect, and hence the dependencies aren't installed during the build. I think I was just lucky to have never deployed a version with a version number with only two sections before. Thanks, and sorry for asking a question I would've found the answer to if I thought about it a little more.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM