DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Dave
Dave

Posted on

npm ERR! @heroku/buildpack-registry not accessible from @heroku-cli/plugin-buildpacks

When trying to push a build over to heroku, you may have encountered the error below:

remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Building on the Heroku-20 stack
remote: -----> Using buildpack: heroku/nodejs
remote: -----> Node.js app detected
remote:        
remote: -----> Creating runtime environment
remote:
remote:        NPM_CONFIG_LOGLEVEL=error
remote:        NODE_VERBOSE=false
remote:        NODE_ENV=production
remote:        NODE_MODULES_CACHE=true
remote:
remote: -----> Installing binaries
remote:        engines.node (package.json):  14.17.1
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 14.17.1...
remote:        Downloading and installing node 14.17.1...       
remote:        Using default npm version: 6.14.13
remote:        
remote: -----> Installing dependencies
remote:        Installing node modules
remote:        npm ERR! @heroku/buildpack-registry not accessible from @heroku-cli/plugin-buildpacks
remote:
remote:        npm ERR! A complete log of this run can be found 
in:
remote:        npm ERR!     /tmp/npmcache.ipzPa/_logs/2022-04-16T23_28_03_880Z-debug.log
remote: 
remote: -----> Build failed
remote:        
remote:        We're sorry this build is failing! You can troubleshoot common issues here:
remote:        https://devcenter.heroku.com/articles/troubleshooting-node-deploys
remote:
remote:        If you're stuck, please submit a ticket so we can help:
remote:        https://help.heroku.com/
remote:
remote:        Love,
remote:        Heroku
remote:
remote:  !     Push rejected, failed to compile Node.js app.    
remote: 
remote:  !     Push failed
Enter fullscreen mode Exit fullscreen mode

And going to the specified link above doesn't seem to address the failure.

Edit: You may also get the below error for the same issue:

npm ERR! valid-url not accessible 
from @heroku-cli/plugin-buildpacks
Enter fullscreen mode Exit fullscreen mode

The Issue

The problem for me was that heroku had no idea which engine to use to install dependencies, so it errored on the dependencies installation of the build. However, the same error will occur if you happen to not have buildpack-registry, so I will lay out some of the possible solutions to this error.

Solutions

Install the buildpacks dependency

Source

The buildpack-registry package may not be installed. Try installing it!

npm i @heroku/buildpack-registry

Install buildpack-registry from the plugins side

It's possible that you may not have buildpacks from the plugins side. Run the below

$ heroku plugins:install buildpack-registry
$ heroku plugins:install buildpacks  
Enter fullscreen mode Exit fullscreen mode

Source

Make sure your engines are both properly defined in package.json

In my case, my issue was that I did not have the proper engines defined under package.json. My package.json looked like this...

{
  "name": "someApp",
  "version": "0.0.0",
  "private": true,
  "engines": {
    "node": "14.17.1",
  },
  "scripts": {
    "start": "node ./bin/www",
    "devstart": "nodemon ./bin/www",
    "heroku-postbuild": "npm run build"

  },
  "dependencies": {
  ...
Enter fullscreen mode Exit fullscreen mode

Notice something?

In fact, if you look at the original log, you'll see that heroku already gave me a hint:

remote: -----> Installing binaries
remote:        engines.node (package.json):  14.17.1
remote:        engines.npm (package.json):   unspecified (use default)
remote:
remote:        Resolving node version 14.17.1...
remote:        Downloading and installing node 14.17.1...       
remote:        Using default npm version: 6.14.13
Enter fullscreen mode Exit fullscreen mode

A quick check at my npm version shows

$ npm --version
8.1.1
Enter fullscreen mode Exit fullscreen mode

heroku is using a different npm than what I am using! This is a big no-no in the dev world.

Adding this in my package.json solved it:

  "engines": {
    "node": "14.17.1",
    "npm": "8.1.1"
  },
Enter fullscreen mode Exit fullscreen mode

Make sure buildpacks is installed globally

If buildpacks is installed locally, I recommend you remove it and install it globally.

npm remove @heroku-cli/plugin-buildpacks
npm i -g @heroku-cli/plugin-buildpacks
Enter fullscreen mode Exit fullscreen mode

Then, remove your node-modules folder and reinstall them with npm i and try to push to heroku again.

Add a post build script

Under the scripts section of your package.json, add

"heroku-postbuild": "npm run build"

Reminders

Don't forget to:

  • commit your changes to heroku before running git push heroku *branch*
  • check out the error logs to find out exactly what part heroku is failing at
  • google for the error message (hopefully by this point you have solved it)
  • make sure you overwrite the existing cache, so push with git push -f heroku master for your first push until it succeeds.

I hope I was able to help someone with this. Happy coding.

Top comments (2)

Collapse
 
exxonose profile image
Ose Daniel

Thanks a lot, this guide was helpful

Collapse
 
warbonnet333 profile image
Vlad

Very helpful! Than you

Why You Need to Study Javascript Fundamentals

The harsh reality for JS Developers: If you don't study the fundamentals, you'll be just another β€œCoder”. Top learnings on how to get to the mid/senior level faster as a JavaScript developer by Dragos Nedelcu.