pnpm: Failed to replace env in config
Verify latest release
- I verified that the issue exists in the latest pnpm release
pnpm version
No response
Which area(s) of pnpm are affected? (leave empty if unsure)
No response
Link to the code that reproduces this issue or a replay of the bug
No response
Reproduction steps
- Create a simple nuxt 3 repo (^3.7.0)
- Create an .npmrc file
- Add the following
@fortawesome:registry = https://npm.fontawesome.com/ //npm.fontawesome.com/:_authToken = ${FONTAWESOME_NPM_AUTH_TOKEN} - Create an .env file
- Add the following
FONTAWESOME_NPM_AUTH_TOKEN=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX - Install fontawesome pro packages
pnpm i @fortawesome/pro-duotone-svg-icons
Describe the Bug
When trying to install the packages, I’m getting the following warning.
Issue while reading "path\to\.npmrc". Failed to replace env in config: ${FONTAWESOME_NPM_AUTH_TOKEN}
Expected Behavior
According to the docs, it should read the variable properly.
Which Node.js version are you using?
16.20.2
Which operating systems have you used?
- macOS
- Windows
- Linux
If your OS is a Linux based, which one it is? (Include the version if relevant)
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 11
- Comments: 17 (5 by maintainers)
Since other pm’s have that feature we should change that to a feature request “Support loading .env files on execution”. Especially in enterprise this is common to not have tokens in config files on employee desktops.
exportthe env variable defined in.envandsourceit will work..env
Run:
FWIW this is indeed not working for me either (locally):
But this is working (see the removed curly braces):
However, it does work locally (Mac OS Sequoia), but it works in reverse in GitHub Workflows… So locally I have my
.npmrcset to$FONTAWESOME_NPM_AUTH_TOKEN, but on GitHub CI, I manually recreate the.npmrcwith${FONTAWESOME_NPM_AUTH_TOKEN}😢@zkochan PNPM seems to be working as expected here. .env files are not supported by NPM though Yarn added .env support about a year and a half ago (https://github.com/yarnpkg/berry/issues/4718 / https://yarnpkg.com/configuration/yarnrc#injectEnvironmentFiles).
I’d be curious though, is there another way of separating out secrets in .npmrc from the non-secret configuration information stored inside it? In my case, I use .npmrc to store both the NPM_TOKEN and PNPM configurations e.g. publish-branch. I would prefer to be able to check-in the .npmrc file since it has non-secret configuration settings but I can’t since it contains the NPM_TOKEN. Ideally, I’d be able to place an env file like .env or .env.pnpm (to avoid conflicts) that I can git-ignore and properly version the .npmrc.
Example:
.npmrc
.env.pnpm
Second to @muuvmuuv
I’m having the same issue on Fedora 41 w/ Zsh.
echo $FONTAWESOME_NPM_TOKENreturns the key.The content of my .npmrc is:
Also tried using
_usernameand_passwordbut it doesn’t matter, the env variables are not injected in the .npmrc file.This is what I get when I run
pnpm config list:Versions:
Node 22.11.0 PNPM 9.13.2
@zkochan, take a look here.
https://docs.npmjs.com/cli/v9/configuring-npm/npmrc/
Come on guys!