Closed shezankazi closed 6 years ago
Howdy @shezankazi 😄
I'm not personally familiar with what you're trying to do, but here's some ideas that might help:
The simplest reason for differences between local & Heroku deployment is that some files, like .npmrc in this case, are not committed to git.
Confirm the git status
does not show that the file is untracked.
When using config vars like NPM_TOKEN
for the build, anytime the var is changed, a new commit must be pushed to trigger a fresh build with the new value. You can push an empty commit to do this:
git commit --allow-empty -m deploy
git push heroku master
# …or if you're working on a branch, replace $BRANCH_NAME for this command,
git push heroku $BRANCH_NAME:master
The npm docs show that the .npmrc file only requires one line, and that it starts with //
,
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
I think those other options you specify are for publishing, which is not normally done from an app using a private package. Maybe those confuse it when building on Heroku.
The npm docs list four different sources for .npmrc,
Confirm that these aren't somehow overriding or conflicting in some way locally that would allow remote deployment to fail.
Hopefully one of these helps! There's no practical reason I can imagine that would make npm registry private scoped packages work locally but not when deployed.
One other idea:
If you're using a self-hosted private npm registry that restricts access by IP address, then it's possible that the Heroku build process does not have access.
@mars Thanks for the quick reply. I tried all your suggestions and in the end it turns out the error was that my .env variables did not start with REACT APP
. Sorry for the post :-(
Which env vars needed the prefix? NPM_TOKEN
does not need a prefix.
In fact if you set REACT_APP_NPM_TOKEN
(do not do this) the secret token value will be included in the javascript bundle, accessible publicly to anyone who can view the source of the React app. That’s a security vulnerability exposing all of your private modules in the registry.
Did not know that!! Thanks @mars!
The error
my package.json
my .npmrc
Including the scoped package from npm works locally but not when deploying to heroku.