Private NPM packages in a React Native app

Hello! I’m attempting to use Bitrise to build my React Native application. Bitrise detected React Native perfectly, but when it attempts to install packages (running npm install) it fails with a 404 error from NPM on one of our private NPM packages.

I’ve tried to search around for a solution to this, the only thing I can find is documentation from NPM stating that I need to declare an NPM_TOKEN environment variable which matches my token in ~/.npmrc. I’ve added this as a Secret and an Environment Variable in my Bitrise workflow but the issue persists. Is there something I’m missing here?

Any help is greatly appreciated!

1 Like

I answered my own question! Apparently, the NPM_TOKEN parameter is only respected by Heroku. As a result, the only solution is to place the token in ~/.npmrc on the CI server. I’ve added a script to my Workflow to run the following, which copies the NPM_TOKEN variable from the Workflow Secrets to the ~/.npmrc file…

# fail if any commands fails
set -e
# debug log
set -x

# write your script here
echo "//${NPM_TOKEN}" > ~/.npmrc

# or run a script from your repository, like:
# bash ./path/to/
# not just bash, e.g.:
# ruby ./path/to/script.rb

Thanks for reporting the solution @jessedunlap, I’m sure it’ll help others in the future! :wink:

Happy Building! :slight_smile:

This saved me after hours of trying to get it to run. Thx man