heroku / buildpacks-nodejs

Heroku's Cloud Native Buildpacks for Node.js applications.
BSD 3-Clause "New" or "Revised" License
24 stars 14 forks source link

Improper engines.npm field causes error in `Checking Node.js version` #891

Open lilacstella opened 2 months ago

lilacstella commented 2 months ago

When the package.json has invalid content for fields in the engine, the Checking Node.js versionstep of the buildpack throws an error that says Could not parse package.json. No valid ranges could be parsed at line ... column .... However, when using yarn locally, the installation is successful without any warnings or errors. This could lead to confusion when developers have the same repo config working locally but not on Heroku.

Reproducing Steps

run pack build using heroku-24 builder on a package.json (e.g. this one in Discourse) that has "please-use-yarn" as the content for the field engines.npm.

Expected outcome

The buildpack should either warn the user that there is invalid content more explicitly right before or after the error, provide suggestions for what could possibly be the problem, or ignore the problem and proceed with using yarn (akin to local yarn behavior).

Actual result

===> ANALYZING
Restoring data for SBOM from previous image
===> DETECTING
3 of 5 buildpacks participating
heroku/nodejs-engine 3.2.7
heroku/nodejs-yarn   3.2.7
heroku/ruby          3.0.0
===> RESTORING
===> BUILDING

[Heroku Node.js Engine Buildpack]

[Checking Node.js version]

[Error: Node.js engine package.json error]
Couldn't parse package.json: Could not parse package.json. No valid ranges could be parsed at line 82 column 29
ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle: failed with status code: 51