title: Yarn with .npmrc and authentication
body: <p>I have encountered an issue that I'm not sure how to resolve in the best way possible. Here it is:</p>
  
  <p>We have recently started using private NPM packages, and are trying to figure out how to tie our local development loop with CI and a Deployment pipeline.</p>
  
  <p>I've looked and started leveraging the NPM_TOKEN variable.
  In CI, we are doing the following:</p>
  
  <pre><code>echo "//registry.yarnpkg.com/:_authToken=$NPM_TOKEN" &gt;&gt; ~/.npmrc
  </code></pre>
  
  <p>This works well, but during deployment on Heroku, we don't have access to home. So to make it work on Heroku we added an .npmrc file to the project directory. This worked well since npm uses environment variables to fill this in.</p>
  
  <p>The problem is that locally, all yarn commands fail with a missing variable. The suggested way on the NPM website (<a href="https://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules" rel="noreferrer">https://blog.npmjs.org/post/118393368555/deploying-with-npm-private-modules</a>) is to add the token to the environment in a .profile. This doesn't seem like the best solution, since the setting is now global, and should be kept per repository.</p>
  
  <p>I've found a similar question here that uses npm but it does not seem to work with yarn.
  <a href="https://stackoverflow.com/questions/53099434/using-auth-tokens-in-npmrc">Using auth tokens in .npmrc</a>
  A comment there also mentions that it does not work for npm and there is no documentation that mention a dotenv file.</p>
  
  <p>Is there a better way to deal with this? Seems like a common issue that should be resolved a long time ago...</p>