opened 04:28PM - 01 Oct 24 UTC
Bug
Needs Triage
### Is there an existing issue for this?
- [X] I have searched the existing iss… ues
### This issue exists in the latest npm version
- [X] I am using the latest npm
### Current Behavior
I am using [NixOS](https://nixos.org/) with [fnm](https://github.com/Schniz/fnm) and set my authentication tokens via [direnv](https://github.com/direnv/direnv). Typically I can add my private registry via the adduser or login command. This command works with (Arch Linux + fnm + direnv) but not from (NixOS + nix-ld + fnm + direnv):
```
npm adduser --registry https://nexus.XXXXXX/repository/npm-hosted/
npm notice Log in on https://nexus.XXXXXX/repository/npm-hosted/
Username: XXXXXXX
Password:
Email: (this IS public)
⠦
npm error code E401
npm error Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm error A complete log of this run can be found in: /home/myuser/.npm/_logs/2024-10-01T14_29_32_111Z-debug-0.log
```
I tried manually setting up my registry and token in .npmrc:
```
@myorg:registry=https://nexus.XXXXXX/repository/npm-hosted/
//nexus.XXXXXX/repository/npm-hosted/:_authToken=NpmToken.xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxx
```
Again, this method works as expected with (Arch Linux + fnm + direnv) but not via (NixOS + nix-ld + fnm + direnv). I receive the same error via whoami:
```
$ npm whoami --registry https://nexus.XXXXXX/repository/npm-hosted/
npm error code E401
npm error Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm error A complete log of this run can be found in: /home/myuser/.npm/_logs/2024-10-01T15_46_05_297Z-debug-0.log
```
I can confirm the environment variable is populating so `direnv` is doing its job:
package.json:
```json
{
...
"name": "myrepo",
"version": "1.12.21",
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"print": "node -e \"console.log(process.env.NPM_TOKEN)\""
},
"dependencies": {
...
}
```
```
$ NPM_TOKEN=foo npm run print
> myrepo@1.12.21 print
> node -e "console.log(process.env.NPM_TOKEN)"
foo
```
### Expected Behavior
With an appropriately set .npmrc, `npm whoami` should return successfully.
### Steps To Reproduce
1. In this environment...
<details>
<summary>configuration.nix</summary>
```nix
### snip
users.users.myuser.packages = with pkgs; [ fnm ];
programs.mtr.enable = true;
programs.nix-ld = {
enable = true;
libraries = with pkgs; [
curl
glib
icu
libdrm
libusb1
libuuid
nspr
nss
openssl
stdenv.cc.cc
zlib
];
};
home-manager.users.myuser.programs.direnv.enable = true;
### snip
```
</details>
2. With this config...
<details>
<summary>.npmrc</summary>
```
@myorg:registry=https://nexus.XXXXXX/repository/npm-hosted/
//nexus.XXXXXX/repository/npm-hosted/:_authToken=NpmToken.xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxx
```
</details>
4. Run...
```
npm whoami
npm whoami --registry https://nexus.XXXXXX/repository/npm-hosted/
```
6. See error...
```
$ npm whoami
npm error code ENEEDAUTH
npm error need auth This command requires you to be logged in.
npm error need auth You need to authorize this machine using `npm adduser`
npm error A complete log of this run can be found in: /home/myuser/.npm/_logs/2024-10-01T16_00_18_905Z-debug-0.log
$ npm whoami --registry https://nexus.XXXXXX/repository/npm-hosted/
npm error code E401
npm error Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm error A complete log of this run can be found in: /home/myuser/.npm/_logs/2024-10-01T16_00_27_244Z-debug-0.log
```
This can be reproduced using bash, fish, or zsh.
### Environment
- npm: 10.8.1
- Node.js: 20.16.0
- OS Name:
```
uname -a
Linux selkie 6.10.5 #1-NixOS SMP PREEMPT_DYNAMIC Wed Aug 14 13:34:38 UTC 2024 x86_64 GNU/Linux
```
- System Model Name:
```
$ lscpu | grep "Model name"
Model name: Intel(R) Core(TM) Ultra 9 185H
```
- npm config:
```ini
; "user" config from /home/myuser/.npmrc
; @explorelearning:registry = "https://nexus.XXXXXX/repository/npm-hosted/" ; overridden by project
; //nexus.XXXXXX/repository/npm-hosted/:_authToken = (protected) ; overridden by project
; "project" config from /home/myuser/code/myrepo/.npmrc
@explorelearning:registry = "https://nexus.XXXXXX/repository/npm-hosted/"
//nexus.XXXXXX/repository/npm-hosted/:_authToken = (protected)
; node bin location = /home/myuser/.local/share/fnm/node-versions/v20.16.0/installation/bin/node
; node version = v20.16.0
; npm local prefix = /home/myuser/code/myrepo
; npm version = 10.8.1
; cwd = /home/myuser/code/myrepo
; HOME = /home/myuser
; Run `npm config ls -l` to show all defaults
```
Current Behavior
I am using fnm to install and manage my node.js and npm version. I set my authentication tokens via direnv . Typically I can add my private registry via the adduser or login command. This command works with (Arch Linux + fnm + direnv) but not from (NixOS + nix-ld + fnm + direnv):
npm adduser --registry https://nexus.XXXXXX/repository/npm-hosted/
npm notice Log in on https://nexus.XXXXXX/repository/npm-hosted/
Username: XXXXXXX
Password:
Email: (this IS public)
⠦
npm error code E401
npm error Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm error A complete log of this run can be found in: /home/myuser/.npm/_logs/2024-10-01T14_29_32_111Z-debug-0.log
I tried manually setting up my registry and token in .npmrc:
@myorg:registry=https://nexus.XXXXXX/repository/npm-hosted/
//nexus.XXXXXX/repository/npm-hosted/:_authToken=NpmToken.xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxx
Again, this method works as expected with (Arch Linux + fnm + direnv) but not via (NixOS + nix-ld + fnm + direnv). I receive the same error via whoami:
$ npm whoami --registry https://nexus.XXXXXX/repository/npm-hosted/
npm error code E401
npm error Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm error A complete log of this run can be found in: /home/myuser/.npm/_logs/2024-10-01T15_46_05_297Z-debug-0.log
I can confirm the environment variable is populating so direnv
is doing its job:
package.json:
{
...
"name": "myrepo",
"version": "1.12.21",
"private": true,
"workspaces": [
"packages/*"
],
"scripts": {
"print": "node -e \"console.log(process.env.NPM_TOKEN)\""
},
"dependencies": {
...
}
$ NPM_TOKEN=foo npm run print
> myrepo@1.12.21 print
> node -e "console.log(process.env.NPM_TOKEN)"
foo
Expected Behavior
With an appropriately set .npmrc, npm whoami
should return successfully.
Steps To Reproduce
In this environment…
configuration.nix
### snip
users.users.myuser.packages = with pkgs; [ fnm ];
programs.mtr.enable = true;
programs.nix-ld = {
enable = true;
libraries = with pkgs; [
curl
glib
icu
libdrm
libusb1
libuuid
nspr
nss
openssl
stdenv.cc.cc
zlib
];
};
home-manager.users.myuser.programs.direnv.enable = true;
### snip
With this config…
.npmrc
@myorg:registry=https://nexus.XXXXXX/repository/npm-hosted/
//nexus.XXXXXX/repository/npm-hosted/:_authToken=NpmToken.xxxxxxx-xxxxx-xxxx-xxxx-xxxxxxxxxxxx
Run…
npm whoami
npm whoami --registry https://nexus.XXXXXX/repository/npm-hosted/
See error…
$ npm whoami
npm error code ENEEDAUTH
npm error need auth This command requires you to be logged in.
npm error need auth You need to authorize this machine using `npm adduser`
npm error A complete log of this run can be found in: /home/myuser/.npm/_logs/2024-10-01T16_00_18_905Z-debug-0.log
$ npm whoami --registry https://nexus.XXXXXX/repository/npm-hosted/
npm error code E401
npm error Unable to authenticate, need: BASIC realm="Sonatype Nexus Repository Manager"
npm error A complete log of this run can be found in: /home/myuser/.npm/_logs/2024-10-01T16_00_27_244Z-debug-0.log
This can be reproduced using bash, fish, or zsh.
Environment
npm: 10.8.1
Node.js: 20.16.0
OS Name:
uname -a
Linux selkie 6.10.5 #1-NixOS SMP PREEMPT_DYNAMIC Wed Aug 14 13:34:38 UTC 2024 x86_64 GNU/Linux
$ lscpu | grep "Model name"
Model name: Intel(R) Core(TM) Ultra 9 185H
; "user" config from /home/myuser/.npmrc
; @explorelearning:registry = "https://nexus.XXXXXX/repository/npm-hosted/" ; overridden by project
; //nexus.XXXXXX/repository/npm-hosted/:_authToken = (protected) ; overridden by project
; "project" config from /home/myuser/code/myrepo/.npmrc
@explorelearning:registry = "https://nexus.XXXXXX/repository/npm-hosted/"
//nexus.XXXXXX/repository/npm-hosted/:_authToken = (protected)
; node bin location = /home/myuser/.local/share/fnm/node-versions/v20.16.0/installation/bin/node
; node version = v20.16.0
; npm local prefix = /home/myuser/code/myrepo
; npm version = 10.8.1
; cwd = /home/myuser/code/myrepo
; HOME = /home/myuser
; Run `npm config ls -l` to show all defaults