Using GitHub Package Registry with Netlify

This took me too long to figure out. I hope it helps you.

Here’s the best way I’ve found to get GitHub Packages working with a Netlify build.

  1. Add this file to your repo. I put it at .npmrc-netlify in the root of the project.

This keeps it from interfering with any .npmrc you might already have and need for local development.

@orgname:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${GITHUB_PACKAGES_KEY}
legacy-peer-deps=true

Remember to update the org name.


2. Next, in your netlify.toml, add this:

[build.environment]
  NPM_CONFIG_USERCONFIG = ".npmrc-netlify"

3. Then last step is setting the GITHUB_PACKAGES_KEY in your projects environment variables.