Skip to content
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

[BUG] config prefix cannot be changed from project config in ~/.npmrc #7501

Closed
2 tasks done
Konfekt opened this issue May 10, 2024 · 13 comments
Closed
2 tasks done

[BUG] config prefix cannot be changed from project config in ~/.npmrc #7501

Konfekt opened this issue May 10, 2024 · 13 comments
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x

Comments

@Konfekt
Copy link

Konfekt commented May 10, 2024

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

With a prefixsetting in ~/.npmrc pointing to a custom directory to install the user's global packages to with npm 10.5.0 on Ubuntu 22.04 and Opensuse 15.5, the error message introduced in #6685 shows up every time.

Expected Behavior

No error message as previously or instructions how to fix the prefix

Steps To Reproduce

Add a prefixsetting in ~/.npmrc pointing to a custom directory to install the user's global packages to.
Now, with npm 10.5.0 on Ubuntu 22.04 and Opensuse 15.5, this error message shows up every time.

Environment

  • npm: 10.05
  • Node.js: 20.13.1
  • OS Name: Ubuntu 20.04
  • System Model Name: Dell Latitude
  • npm config:
prefix=/home/konfekt/.local/share/npm-packages
@Konfekt Konfekt added Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x labels May 10, 2024
@milaninfy
Copy link
Contributor

@Konfekt value for prefix can not be changed from the project level .npmrc. if you want to change location of user's global packages, consider changing prefix value for user level .npmrc file. Checkout this documentation for more information on .npmrc https://docs.npmjs.com/cli/v10/configuring-npm/npmrc

@Konfekt
Copy link
Author

Konfekt commented May 10, 2024

But does the linked documentation not refer to ~/.npmrc as per-user config file ?

@milaninfy
Copy link
Contributor

milaninfy commented May 10, 2024

yes it does. I am guessing that you might have ~/.npmrc already as per user config file. Do you also have .npmrc at your project level? Please share output of npm config ls from the project directory where you are getting this error.

@wraithgar
Copy link
Member

Please do not abbreviate when making a bug report. The actual output of the error message tells us exactly what file is trying to set prefix. The first line of npm config list also should show that error. It's impossible to triage this issue without that info.

@Konfekt
Copy link
Author

Konfekt commented May 10, 2024

No, I only use npm to install executables, but do not use it for a project.

$ npm


npm ERR! config prefix cannot be changed from project config: /home/konfekt/.npmrc.
npm <command>

Usage:

npm install        install all the dependencies in your project
npm install <foo>  add the <foo> dependency to your project
npm test           run this project's tests
npm run <foo>      run the script named <foo>
npm <command> -h   quick help on <command>
npm -l             display usage info for all commands
npm help <term>    search for help on <term>
npm help npm       more involved overview

All commands:

    access, adduser, audit, bugs, cache, ci, completion,
    config, dedupe, deprecate, diff, dist-tag, docs, doctor,
    edit, exec, explain, explore, find-dupes, fund, get, help,
    help-search, hook, init, install, install-ci-test,
    install-test, link, ll, login, logout, ls, org, outdated,
    owner, pack, ping, pkg, prefix, profile, prune, publish,
    query, rebuild, repo, restart, root, run-script, sbom,
    search, set, shrinkwrap, star, stars, start, stop, team,
    test, token, uninstall, unpublish, unstar, update, version,
    view, whoami

Specify configs in the ini-formatted file:
    /home/konfekt/.config/.npmrc
or on the command line via: npm <command> --key=value

More configuration info: npm help config
Configuration fields: npm help 7 config

npm@10.5.0 /usr/lib64/node_modules/npm18

@wraithgar
Copy link
Member

Is there a package.json file in /home/konfekt?

@Konfekt
Copy link
Author

Konfekt commented May 11, 2024

Hello! No, there is none. The home folder is rather limpid.

@Konfekt
Copy link
Author

Konfekt commented May 11, 2024

This seems to originate from

return this.#loadFile(projectFile, 'project')

So resolve(this.localPrefix, '.npmrc') != this.#get('userconfig') would be satisfied.

@Konfekt
Copy link
Author

Konfekt commented May 12, 2024

The localPrefix seems in

this.localPrefix = this.cwd
to be set to the current working directory, ~/, say, so that the project config and user config collide.

In other directories, different from ~/, npm no longer shows the warning introduced in #6685

Why this warning inside ~/ specifically ?

@wraithgar
Copy link
Member

what does npm config list show. In full. There is still not enough here to reproduce the error. Please note that the issue template asks for

; copy and paste output from npm config ls here

@Konfekt
Copy link
Author

Konfekt commented May 13, 2024

Here we go.
Regarding the referred to code lines, I think this issue is to be expected, though.
Are you sure you cannot reproduce, setting prefix in ~/.npmrc?

$ npm config ls -l

; "default" config from default values

_auth = (protected) 
access = null 
all = false 
allow-same-version = false 
also = null 
audit = true 
audit-level = null 
auth-type = "web" 
before = null 
bin-links = true 
browser = null 
ca = null 
cache = "/home/konfekt/.npm" 
cache-max = null 
cache-min = 0 
cafile = null 
call = "" 
cert = null 
cidr = null 
color = true 
commit-hooks = true 
cpu = null 
depth = null 
description = true 
dev = false 
diff = [] 
diff-dst-prefix = "b/" 
diff-ignore-all-space = false 
diff-name-only = false 
diff-no-prefix = false 
diff-src-prefix = "a/" 
diff-text = false 
diff-unified = 3 
dry-run = false 
editor = "vim" 
engine-strict = false 
expect-result-count = null 
expect-results = null 
fetch-retries = 2 
fetch-retry-factor = 10 
fetch-retry-maxtimeout = 60000 
fetch-retry-mintimeout = 10000 
fetch-timeout = 300000 
force = false 
foreground-scripts = false 
format-package-lock = true 
fund = true 
git = "git" 
git-tag-version = true 
global = false 
global-style = false 
globalconfig = "/home/konfekt/.local/share/npm-packages/etc/npmrc" 
heading = "npm" 
https-proxy = null 
if-present = false 
ignore-scripts = false 
include = [] 
include-staged = false 
include-workspace-root = false 
init-author-email = "" 
init-author-name = "" 
init-author-url = "" 
init-license = "ISC" 
init-module = "/home/konfekt/.npm-init.js" 
init-version = "1.0.0" 
init.author.email = "" 
init.author.name = "" 
init.author.url = "" 
init.license = "ISC" 
init.module = "/home/konfekt/.npm-init.js" 
init.version = "1.0.0" 
install-links = false 
install-strategy = "hoisted" 
json = false 
key = null 
legacy-bundling = false 
legacy-peer-deps = false 
libc = null 
link = false 
local-address = null 
location = "user" 
lockfile-version = null 
loglevel = "notice" 
logs-dir = null 
logs-max = 10 
; long = false ; overridden by cli
maxsockets = 15 
message = "%s" 
node-options = null 
noproxy = [""] 
npm-version = "10.5.0" 
offline = false 
omit = [] 
omit-lockfile-registry-resolved = false 
only = null 
optional = null 
os = null 
otp = null 
pack-destination = "." 
package = [] 
package-lock = true 
package-lock-only = false 
parseable = false 
prefer-dedupe = false 
prefer-offline = false 
prefer-online = false 
; prefix = "/usr" ; overridden by project
preid = "" 
production = null 
progress = true 
provenance = false 
provenance-file = null 
proxy = null 
read-only = false 
rebuild-bundle = true 
registry = "https://registry.npmjs.org/" 
replace-registry-host = "npmjs" 
save = true 
save-bundle = false 
save-dev = false 
save-exact = false 
save-optional = false 
save-peer = false 
save-prefix = "^" 
save-prod = false 
sbom-format = null 
sbom-type = "library" 
scope = "" 
script-shell = null 
searchexclude = "" 
searchlimit = 20 
searchopts = "" 
searchstaleness = 900 
shell = "/bin/zsh" 
shrinkwrap = true 
sign-git-commit = false 
sign-git-tag = false 
strict-peer-deps = false 
strict-ssl = true 
tag = "latest" 
tag-version-prefix = "v" 
timing = false 
umask = 0 
unicode = true 
update-notifier = true 
usage = false 
user-agent = "npm/{npm-version} node/{node-version} {platform} {arch} workspaces/{workspaces} {ci}" 
; userconfig = "/home/konfekt/.npmrc" ; overridden by env
version = false 
versions = false 
viewer = "man" 
which = null 
workspace = [] 
workspaces = null 
workspaces-update = true 
yes = null 

; "user" config from /home/konfekt/.config/.npmrc

; prefix = "/home/konfekt/.local/share/npm-packages" ; overridden by project

; "project" config from /home/konfekt/.npmrc

prefix = "/home/konfekt/.local/share/npm-packages" 

; "env" config from environment

userconfig = "/home/konfekt/.config/.npmrc" 

; "cli" config from command line options

long = true

@wraithgar
Copy link
Member

Here's what's happening

  • You have set userconfig to /home/konfekt/.config/.npmrc using environment variables
  • You have reset the prefix from there to /home/konfekt/.local/share/npm-packages
  • Because the .npmrc file in /home/konfekt/.npmrc is no longer the user level config, when you run npm from that directory npm loads it up and considers it the project level config.

I think at this point you need to pare down your config chain, this is not a set up we can support.

@Konfekt
Copy link
Author

Konfekt commented May 13, 2024

Understood, thank you very much for your time and clearing this up. I forgot about this environment variable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 10.x
Projects
None yet
Development

No branches or pull requests

3 participants