Not Working Using An `env var` Within a `.npmrc` File
Answered
Donald Louch posted this in #help-forum
Hello,
I am trying to setup Hugeicons' new NPM Token verification method and can get the package installed when passing the token directly into the
am I missing something?! Do I need to do anything within the
Thanks,
Donald Louch
I am trying to setup Hugeicons' new NPM Token verification method and can get the package installed when passing the token directly into the
npmrc
file! However, I want to pass this though an enviorment variable to be more secure! But when I do, I am unable to install the package as it can't find the token.# .env (tried .env \ .env.local \ .env.development)
// I've tried the following
NEXT_PUBLIC_NPM_TOKEN=thetoken
NPM_TOKEN=thetoken
NEXT_PUBLIC_NPM_TOKEN="thetoken"
NPM_TOKEN="thetoken"
NEXT_PUBLIC_NPM_TOKEN = "thetoken"
NPM_TOKEN = "thetoken"
# .npmrc
; I've tried the following
//registry.npmjs.org/:_authToken=$NEXT_PUBLIC_NPM_TOKEN
//registry.npmjs.org/:_authToken=$NPM_TOKEN
//registry.npmjs.org/:_authToken=${NEXT_PUBLIC_NPM_TOKEN}
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
am I missing something?! Do I need to do anything within the
next.config.js
config file?!Thanks,
Donald Louch
Answered by Donald Louch
I think I have found the solution? There is no need to create a npmrc file for Vercel! You just need to add a
https://vercel.com/guides/using-private-dependencies-with-vercel
NPM_TOKEN
env var into the dashboard within the Vercel project and Vercel will add the appropriate npmrc file 🎉https://vercel.com/guides/using-private-dependencies-with-vercel
24 Replies
this is probably since
env variables aren'tloaded
if running
NPM_TOKEN="thetoken" npm i
works that's the causeDo you know how I can fix this?!
@Donald Louch did you try this
So would it be
If so, then yes I have tried that and still no luck!
// .env
NPM_TOKEN="thetoken" npm i
// .npmrc
//registry.npmjs.org/:_authToken=$NPM_TOKEN
If so, then yes I have tried that and still no luck!
I just tried that and it isn't working either!
wait
you're supposed to do it like
registry.npmjs.org/:_authToken={$NPM_TOKEN}
with the parenthesis
and then you add the token to your bash/zshrc
since it doesn't pick up from .env iirc but i might be wrong
Okay, do you know if I can have that added to vercel for deployment?!
Vercel env's likely gonna work
I'm not sure
try it and see
that was the wrong emoji i thought there was one about tryitandsee
Update: did not work with Vercel 😅
I think I have found the solution? There is no need to create a npmrc file for Vercel! You just need to add a
https://vercel.com/guides/using-private-dependencies-with-vercel
NPM_TOKEN
env var into the dashboard within the Vercel project and Vercel will add the appropriate npmrc file 🎉https://vercel.com/guides/using-private-dependencies-with-vercel
Answer