Cookies
This website uses cookies to improve the user experience, more information on the legal information path.
Notes
0
years
0
mons
0
days
0
hour
0
mins
0
secs
Sat16Mar8:15 PM
This is the background image
2

Possible solution for NPM - Failed to replace env in config: ${NPM_TOKEN}

Tue, Jan 3, 2023

In this short post I am going to show a solution for the Failed to replace env in config: ${{NPM_TOKEN} error that occurs when trying to run a yarn or npm command.

You may have encountered this error at some point when trying to run a yarn or npm command. In my case it was because I published one of my libraries on github and in order to install it from github, I needed a token. This token is generated in github and stored in the system environment variables.

But it is necessary to create an .npmrc file in the root of the project and add the following content:

.npmrc

@xabierlameiro:registry=https://npm.pkg.github.com/
//npm.pkg.github.com/:_authToken=${NPM_TOKEN}

What can happen is that you leave this file outside the project folder and save it in the user folder, for example in my case I saved it in the folder C:\Users\xabierlameiro\.npmrc and that's why I got the error.

To solve it, what I did was:


yarn install --verbose

It showed me the paths where I was looking for the .npmrc file and I realised that I was using it from the user folder.

I deleted it from the user folder and recreated it in the root of the project and it no longer gave me the error.

I hope that if the same thing happens to you, it will help.