I am trying to install a private Github package to a Gatsby project I'm working on that will get deployed to Netlify, but I am continuing to get a 401 Unauthorized...
When I add my token inline, or use my ~/.npmrc file it works and installs fine but doesn't work when I am using a local environment variable.
Here is my .npmrc file...
//npm.pkg.github.com/:_authToken=$NPM_TOKEN
@OWNER:registry=https://npm.pkg.github.com/OWNER
NOTE
I have also tried this with no luck -
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}
@OWNER:registry=https://npm.pkg.github.com/OWNER
How do I get my environment variable to work inside my local project .npmrc file?
UPDATE
I managed to get it working locally by removing the extra the last / from github.com (shown below), but this still doesn't fix the error on the Netlify side.
- //npm.pkg.github.com/:_authToken=$NPM_TOKEN
+ //npm.pkg.github.com:_authToken=$NPM_TOKEN
Any help would be appreciated, thanks.
I got it working but I'm sure there's a better way...
The .npmrc has to be
To get it working locally -
//npm.pkg.github.com:_authToken=$READ_TOKEN
@OWNER:registry=https://npm.pkg.github.com/OWNER
However this returns a 401 unauthorised error on Netlify...
To Get it to work on Netlify -
//npm.pkg.github.com/:_authToken=${READ_TOKEN}
registry=https://npm.pkg.github.com/OWNER
However like-wise this doesn't work locally...
At the moment I'm having to switch them out manually depending on whether I'm working locally or using it in production but as I say I think there must be a better way to do that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With