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

Improve error messaging when installing an incompatible npm version #1134

Merged
merged 6 commits into from
Sep 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## main

- Improved error messaging when installing an incompatible npm version.
- Added Node.js version 18.18.0.
- Added Node.js version 20.7.0.

Expand Down
6 changes: 4 additions & 2 deletions lib/binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ install_npm() {
echo "npm $npm_version already installed with node"
else
echo "Bootstrapping npm $version (replacing $npm_version)..."
if ! npm install --unsafe-perm --quiet -g "npm@$version" 2>@1>/dev/null; then
echo "Unable to install npm $version; does it exist?" && false
if ! npm install --unsafe-perm --quiet --no-audit --no-progress -g "npm@$version" >/dev/null; then
echo "Unable to install npm $version. " \
"Does npm $version exist? " \
"Is npm $version compatible with this Node.js version?" && false
fi
# Verify npm works before capturing and ensure its stderr is inspectable later
npm --version 2>&1 1>/dev/null
Expand Down
1 change: 1 addition & 0 deletions test/fixtures/npm-version-incompat/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A fake README, to keep npm from polluting stderr.
13 changes: 13 additions & 0 deletions test/fixtures/npm-version-incompat/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "node-buildpack-test-app",
"version": "0.0.1",
"description": "node buildpack integration test app",
"repository" : {
"type" : "git",
"url" : "http://github.com/example/example.git"
},
"engines": {
"node": "16.x",
"npm": "10.x"
}
}
9 changes: 8 additions & 1 deletion test/run
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,13 @@ testNpmVersionSpecific() {
assertCapturedSuccess
}

testNpmVersionIncompatible() {
compile "npm-version-incompat"
assertCaptured "Unable to install npm 10.x"
assertCaptured "Is npm 10.x compatible with this Node.js version?"
assertCapturedError
}

testFailingBuild() {
compile "failing-build"
assertCaptured "Build failed"
Expand Down Expand Up @@ -1139,7 +1146,7 @@ testNodeEnvNpmConfigProductionFalse() {
assertCaptured "preinstall: production"
assertCaptured "postinstall: production"
assertCaptured "heroku-postbuild: production"
assertCapturedSuccess
assertEquals "Expected successful exit code" "0" "${RETURN}"
}

# Avoid this issue
Expand Down
Loading