Can't use the env variables in the package json


In my ReactJS project, I am trying to use a dependency directly from a private GitHub repository. This was very helpful and I was able to use the dependency.

The problem is that I can’t use the credential using an environment variable.

npm install git+https://${GIT_TOKEN}

The ${GIT_TOKEN} is parsed as a string.

I tried to echo the value in pre:install and it worked there but not during the build.

Will I have to create my own build script/process? If yes, is there any guide or something?


1 Like


Did you find a solution for this?
This doc, which was also helpful, precise:

Keep tokens private

You can avoid committing access tokens in public repositories by storing them as environment variables in your site or team settings.

But I don’t find any way to use the environment variables in the package.json and the guide about env variable doesn’t mention this either.