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.

  1. Next, in your netlify.toml, add this:
  NPM_CONFIG_USERCONFIG = ".npmrc-netlify"
  1. Then last step is setting the GITHUB_PACKAGES_KEY in your projects environment variables.