Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

npm downgraded to 5.x if default version is 10.x #1140

Closed
sdaicz opened this issue Sep 19, 2023 · 1 comment · Fixed by #1141
Closed

npm downgraded to 5.x if default version is 10.x #1140

sdaicz opened this issue Sep 19, 2023 · 1 comment · Fixed by #1141
Labels

Comments

@sdaicz
Copy link

sdaicz commented Sep 19, 2023

Describe the bug
Now that the default npm version for node 20.7 is 10.1.0, if an npm version is not specified it will be incorrectly downgraded to 5.x

To Reproduce
Steps to reproduce the behavior:

  1. Specify "engines": { "node": "20.x" } in your package.json file (note that "npm" is not specified)

  2. Build your app on Heroku

  3. In the build log you'll see something like:

    Downloading and installing node 20.7.0...
    Detected package-lock.json: defaulting npm to version 5.x.x
    Bootstrapping npm 5.x.x (replacing 10.1.0)...
    npm 5.10.0 installed
    
  4. Your build will probably fail with some obscure error message later

Versions (please complete the following information):

  • Heroku Stack: heroku-22
  • Node Version: 20.7.0
  • NPM Version: 10.1.0
  • Buildpack Version: heroku/nodejs v221

Additional context
The issue originates from this line, which only looks at the first character of the default node version:

if $npm_lock && [ "$version" == "" ] && [ "${npm_version:0:1}" -lt "5" ]; then

@sdaicz sdaicz added the bug label Sep 19, 2023
@davekaro
Copy link

Similarly, I noticed some new warnings present that are due to the same bug in the code.

 !     This version of npm (10.1.0) does not support package-lock.json. Please
       update your npm version in package.json.
       https://devcenter.heroku.com/articles/nodejs-support#specifying-an-npm-version

which comes from

if $npm_lock && [ "${npm_version:0:1}" -lt "5" ]; then
.

I searched the code and found it may also present a problem here

if [ "${npm_version:0:1}" -lt "2" ]; then

colincasey added a commit that referenced this issue Sep 20, 2023
Several checks of the `major` version of npm being used were only accounting for the first character of the version string. E.g.; version `10.1.0` would be treated as `major=1` instead of `major=10`.

This PR changes those checks to split on `.` characters using `cut` and read the `major` version as the first field and adds a test to verify.

Fixes #1140
colincasey added a commit that referenced this issue Sep 25, 2023
* Fix downgrade to npm 5.x when using version 10.x or greater

Several checks of the `major` version of npm being used were only accounting for the first character of the version string. E.g.; version `10.1.0` would be treated as `major=1` instead of `major=10`.

This PR changes those checks to split on `.` characters using `cut` and read the `major` version as the first field and adds a test to verify.

Fixes #1140
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants