I'm not able to get my project .npmrc file to recognize any of the environment variables set at three different scopes (project, user, global).
The only way I'm able to install a private module is by hardcoding the api key into the .npmrc file, which is obviously unacceptable since .npmrc is watched by git.
I've tried creating environment variables as the npm-config
docs suggest, i.e.:
- in a project
.env
file, where both a.npmrc
file and a.env
file are siblings ofpackage.json
, i.e.:fontawesome_pro_token=ABC123
- in a user config file, i.e.:
$ npm set fontawesome_pro_token ABC123
- in a global config file, i.e.:
$ npm set fontawesome_pro_token ABC123 --global
When I reference the env variable in the project .npmrc
file, i.e.:
@fortawesome:registry=https://npm.fontawesome.com/
//npm.fontawesome.com/:_authToken=${fontawesome_pro_token}
I get this error:
Error: Failed to replace env in config: ${fontawesome_pro_token}
When I remove the curly braces around the variable name (as this stack overflow answer suggests), I get the following error:
npm ERR! 401 Unauthorized
Any advice on how to config npm to read env variables?
Incidentally -- if deploying private modules to Netlify, Netlify expects the .npmrc file to use the curly braces for env var syntax, see this gist. I can confirm that using the curly brace syntax in a git watched npmrc file, along with setting a build env var in the netlify project admin dashboard, indeed works.