Skip to content

fix: Fix using environment variables to specify prefix #8415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: latest
Choose a base branch
from

Conversation

MarcellPerger1
Copy link

Previously, the code in workspaces/config/lib/index.js didn't take into account the environment variables when determining Config.localPrefix.
This means that commands using localPrefix could previously behave unexpectedly or fail (if the current working directory isn't part of a package) when the prefix is specified using NPM_CONFIG_PREFIX=... .

This PR fixes this by simply checking the environment variables as well using the Config.#get('prefix', 'env')

References

Fixes #4467.

@MarcellPerger1 MarcellPerger1 requested a review from a team as a code owner July 3, 2025 21:43
@wraithgar
Copy link
Member

This is a danger area and we should make sure we know if this was intentional before adding it. Setting the prefix before certain operations has caused bugs in the past.

I don't know for sure that this is a problem, but caution is in order here. Setting the prefix in npm is tricky because by the time we're parsing it we have sometimes already assumed we know what the prefix is.

@MarcellPerger1
Copy link
Author

MarcellPerger1 commented Jul 15, 2025

I don't really understand why this could cause problems. We're already setting localPrefix from the CLI arguments in the same way so surely doing the same with the environment variable won't cause any problems (well unless they were there to begin with). The environment variable is just another source for the same data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] NPM_CONFIG_PREFIX is ignored during install
2 participants