DEV Community

loading...
Cover image for Heroku & Github (private) packages - Just Work™

Heroku & Github (private) packages - Just Work™

johan_du_toit profile image Johan du Toit ・1 min read

Cut to the chase

Like many developers out there, we work on side projects from time to time. Sometimes it's to learn, to have fun or to make money. Regardless of the reason, we often throw in the towel due to burnout, loss of interest or that frustrating service/tool that should just work™ but doesn't.

I recently murmured "Why isn't this just working as stated!" while attempting to get Heroku to install my private Github packages. I headed to my trusty ol' friend, Google, to scour the internet for an answer only to be repeatedly told that I need to 'commit an .npmrc file' with the registry URL (with auth token) and getting absolutely nowhere.

On the verge of giving up, I decided to head into the Github actions source code. After all I was able to publish my package to my private Github registry in a CI environment.

Below is the code that dynamically creates the .nmprc file before the Heroku build (using the heroku-prebuild hook), using values from the environment variables.

The good stuff

  1. Add the auth-npm.js script to your project (I add it to my bin directory)

  2. Update package.json

Drop a comment below if you're running into trouble and/or if you have improvements!

Remember to #KeepHavingFun

Discussion (3)

pic
Editor guide
Collapse
mauriciord profile image
Maurício R Duarte

this script is wrong

fs.writeFileSync(fileLocation, contents);

where is the fileLocation declaration?

Collapse
johan_du_toit profile image
Johan du Toit Author • Edited

Probably way to late, but fileLocation should be the npmrc variable. Will update the script.

Collapse
leesmith profile image
Lee Smith 🍻

Heroku clearly documents how to do this but it simply doesn't work for my review app. Quite the head scratcher...