# Accessing private Github package registry

**URL:** <https://answers.netlify.com/t/accessing-private-github-package-registry/17199>\
**Category:** Support\
**Tags:** authentication, netlify-newbie, building\
**Created:** [June 18, 2020, 8:11am UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199 "2020-06-18T08:11:30Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mrslump](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mrslump](https://answers.netlify.com/u/mrslump)\
**Post date:** [June 18, 2020, 8:11am UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/1 "2020-06-18T08:11:30Z")

</div>

Our site build fetches dependencies from a private Github package registry.  
How do I set up the build to use Github access token to authenticate to GH packages?

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [June 23, 2020, 11:36pm UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/3 "2020-06-23T23:36:03Z")

</div>

Hi @mrslump and sorry to be slow to get back to you! None of our Support team use that GH feature, but we found someone who did and they clued us in to their workflow.

This is the flow that we use for one of our private GH0hosted dependencies. This is the entire npmrc on that codebase:

```auto
@netlify:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=${NPM_TOKEN} 

```

We set $NPM\_TOKEN in our site environment variables, on the build & deploy settings page, and then .npmrc lives next to package.json and things should Just Work.

Note that if you use that locally, you will need to have $NPM\_TOKEN set locally too! Should work the same on Netlify and locally 🙂

---

<div class="post-metadata">

**Author:** ![mrslump](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mrslump](https://answers.netlify.com/u/mrslump)\
**Post date:** [June 24, 2020, 5:29pm UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/4 "2020-06-24T17:29:05Z")

</div>

Thanks!

In dev sandboxes we configure the NPM token in `~/.npmrc` and would like to have it working in local environments without having to tweak additional environment variables.  
I was planning to create a script for setting this up when building on Netlify.

However, I’m currently having some problems with this.  
It seems that right after Netlify clones my git repo it runs `yarn install` automatically and only then runs the build script I’ve configured.

Is it possible to get a custom command/script to run before or instead of `yarn install`?

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [June 26, 2020, 12:53am UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/5 "2020-06-26T00:53:23Z")

</div>

Unfortunately no, you cannot do anything before we install dependencies automatically UNLESS your site has no dependency installation config (no package.json/yarn.lock), which seems like it isn’t an option for you.

We are working to extend build plugins ([Build Plugins | Netlify Docs](https://docs.netlify.com/configure-builds/build-plugins/)) to allow scripts to run before dependency installation, and I will report back in this thread once we ship that feature, since it will unblock you in some ways at least.

I don’t know a good way to avoid using npmrc, so not sure how to unblock you further on that requirement around your local env.

---

<div class="post-metadata">

**Author:** ![mrslump](https://avatars.discourse-cdn.com/v4/letter/m/2bfe46/32.png) [@mrslump](https://answers.netlify.com/u/mrslump)\
**Post date:** [June 26, 2020, 6:05am UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/7 "2020-06-26T06:05:25Z")

</div>

Thanks for the update!

Can you give any tentative estimates on what the schedule for making this feature available could be?

---

<div class="post-metadata">

**Author:** ![perry](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/perry/32/16_2.png) [@perry](https://answers.netlify.com/u/perry)\
**Post date:** [June 29, 2020, 5:09pm UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/8 "2020-06-29T17:09:38Z")

</div>

hi @mrslump, you might keep an eye here:

> <https://github.com/netlify/build/issues/1149>
>
> \*\*Which problem is this feature request solving?\*\*
> 
> I was hoping to be able to… use build plugins to solve our npmrc problem \[described and workaround over here\](https://community.netlify.com/t/common-issue-using-private-npm-modules-on-netlify/795/33) but it doesn't seem to be possible, because the plugins are started too late in the process to do so.
> 
> \*\*Describe the solution you'd like\*\*
> 
> The \`onInit\` event launches after all dependencies are installed, so what I would need is something like an \`onPreInstall\` event which allows me to do stuff before npm/yarn install is executed.
> 
> 
> \*\*Describe alternatives you've considered\*\*
> 
> The somewhat hacky workaround as described in the community post.
> 
> \*\*Can you submit a pull request?\*\*
> 
> Not right now but I'll be happy to submit one if this is a possibility and the way forward to implementing such an event.

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [June 29, 2020, 6:59pm UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/9 "2020-06-29T18:59:13Z")

</div>

Just to make sure your question got an answer: we don’t promise delivery dates for code not yet written yet. Following that issue will be your best indicator of work progressing 🙂

---

<div class="post-metadata">

**Author:** ![paulmelero](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/paulmelero/32/4596_2.png) [@paulmelero](https://answers.netlify.com/u/paulmelero)\
**Post date:** [February 17, 2021, 8:13am UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/10 "2021-02-17T08:13:52Z")

</div>

I’ve tried this, and it seems to install the dependency correctly after adding a [Personal Access Token](https://docs.github.com/en/github/authenticating-to-github/creating-a-personal-access-token) as the `NPM_TOKEN` variable in the Build\>Environment settings, but then, on the `build` command, it fails with `Cannot find module '...' or its corresponding type declarations.`. ☹

For support team only:

- This is the log in question: [Netlify App](https://app.netlify.com/teams/gangsthub/builds/602cc81a4456e90007ad2f16)
- And this is the site: [https://g-slim-carousel-docs.netlify.app](https://g-slim-carousel-docs.netlify.app/)

---

<div class="post-metadata">

**Author:** ![fool](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/fool/32/37_2.png) [@fool](https://answers.netlify.com/u/fool)\
**Post date:** [February 26, 2021, 7:56pm UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/11 "2021-02-26T19:56:35Z")

</div>

Hiya @paulmelero and sorry to be slow to get back to you! I think that if the request succeeds (rather than showing an auth error), you’ll probably want to debug what is installed, where as next steps. It’s my guess that it is somehow ending up in the wrong directory, which is not something we control (your build pipeline does).

Have you tried [running your build locally in our build container](https://github.com/netlify/build-image/#running-locally) to see where the output goes, and if it is in a place your build pipeline can find it? If you don’t have local docker, you could get some debug details out of our CI instead with a build command more like:

`npm run build ; ls -lR && cat /opt/buildhome/.npm/_logs/*debug.log && sleep 200 ; false`

This will start your build (we never get to step 2 `npm run export` as far as I can tell), and then show you what files are there, what the debug logs from npm show, and give all that output time to get saved, before intentionally failing the build (since we wouldn’t want to publish your build if the ‘sleep’ command succeeds - it always will).

---

<div class="post-metadata">

**Author:** ![themetzmeier](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/themetzmeier/32/35308_2.png) [@themetzmeier](https://answers.netlify.com/u/themetzmeier)\
**Post date:** [August 17, 2023, 11:57pm UTC](https://answers.netlify.com/t/accessing-private-github-package-registry/17199/12 "2023-08-17T23:57:52Z")

</div>

It looks like this guide should be the definitive answer: [Using GitHub Package Registry with Netlify](https://www.mikecoutermarsh.com/using-github-package-registry-with-netlify/)
