#deno gives 401 unauthorized for imports with an `npm:` specifier, but npm, yarn and pnpm all work?

24 messages · Page 1 of 1 (latest)

civic peak
#

heya!

i'm having difficulty with getting npm: specifiers to work. i've tried them via an import like below, or running via the cli. both give a 401 error for any package (regardless of if it's scoped, unscoped, using a specific npm config registry or anything).

i tried this in all of stable, canary and rc deno versions - all have the same. i'll include debug logs from the latest rc

it used to work a few weeks ago, then it stopped working with all versions for a bit, then i created a new artifactory token and put that in my npmrc and it worked for a few days, and now it's back to not working again?

if it makes any difference, i'm using company vpn. and i had vscode closed and i was using a new terminal for this test, same result :/

both of these don't work and give this error:

error: Error getting response at https://packages.mycompany.com/artifactory/api/npm/npm-remote/@angular/cli for package "@angular/cli": Bad response: 401

{
  "errors" : [ {
    "status" : 401,
    "message" : "Bad credentials"
  } ]
}
import { thing } from 'npm:literally-anything';
deno run -A npm:@angular/cli

i'll add debug logs and configs in the following messages

#

here's my ~/.npmrc (i replaced all instances of my password with "supersecret", all instances of my username with "myusername" and all instances of my company name with "mycompany" - nothing more):

registry=https://packages.mycompany.com/artifactory/api/npm/npm-remote
@mycompanysox:registry=https://packages.mycompany.com/artifactory/api/npm/mycompany-npm/
@fortawesome:registry=https://packages.mycompany.com/artifactory/api/npm/npm-remote-fontawesome/
@mycompany:registry=https://packages.mycompany.com/artifactory/api/npm/mycompany-npm/
//packages.mycompany.com/artifactory/api/npm/mycompany-npm/:_password=supersecret
//packages.mycompany.com/artifactory/api/npm/mycompany-npm/:username=myusername
//packages.mycompany.com/artifactory/api/npm/mycompany-npm/:[email protected]
//packages.mycompany.com/artifactory/api/npm/mycompany-npm/:always-auth=true

//packages.mycompany.com/api/npm/mycompany-npm/:_password=supersecret
//packages.mycompany.com/api/npm/mycompany-npm/:username=myusername
//packages.mycompany.com/api/npm/mycompany-npm/:[email protected]
//packages.mycompany.com/api/npm/mycompany-npm/:always-auth=true

//packages.mycompany.com/artifactory/api/npm/npm-remote-fontawesome/:_password=supersecret
//packages.mycompany.com/artifactory/api/npm/npm-remote-fontawesome/:username=myusername
//packages.mycompany.com/artifactory/api/npm/npm-remote-fontawesome/:[email protected]
//packages.mycompany.com/artifactory/api/npm/npm-remote-fontawesome/:always-auth=true

//packages.mycompany.com/api/npm/npm-remote-fontawesome/:_password=supersecret
//packages.mycompany.com/api/npm/npm-remote-fontawesome/:username=myusername
//packages.mycompany.com/api/npm/npm-remote-fontawesome/:[email protected]
//packages.mycompany.com/api/npm/npm-remote-fontawesome/:always-auth=true

//packages.mycompany.com/artifactory/api/npm/npm-remote-fontawesome/:_password=supersecret
//packages.mycompany.com/artifactory/api/npm/npm-remote-fontawesome/:username=myusername
//packages.mycompany.com/artifactory/api/npm/npm-remote-fontawesome/:[email protected]
//packages.mycompany.com/artifactory/api/npm/npm-remote-fontawesome/:always-auth=true

//packages.mycompany.com/api/npm/npm-remote-fontawesome/:_password=supersecret
//packages.mycompany.com/api/npm/npm-remote-fontawesome/:username=myusername
//packages.mycompany.com/api/npm/npm-remote-fontawesome/:[email protected]
//packages.mycompany.com/api/npm/npm-remote-fontawesome/:always-auth=true

//packages.mycompany.com/artifactory/api/npm/npm-remote/:_password=supersecret
//packages.mycompany.com/artifactory/api/npm/npm-remote/:username=myusername
//packages.mycompany.com/artifactory/api/npm/npm-remote/:[email protected]
//packages.mycompany.com/artifactory/api/npm/npm-remote/:always-auth=true

//packages.mycompany.com/api/npm/npm-remote/:_password=supersecret
//packages.mycompany.com/api/npm/npm-remote/:username=myusername
//packages.mycompany.com/api/npm/npm-remote/:[email protected]
//packages.mycompany.com/api/npm/npm-remote/:always-auth=true
#

debug/backtrace log (replaced my username and company name, changed the ips - rest is the asme):

~ RUST_BACKTRACE=1 DENO_LOG=debug deno run -A npm:@angular/cli                                                                                                 
DEBUG RS - deno::args:932 - Finished config loading.
DEBUG RS - deno::cache::cache_db:168 - Opening cache /Users/myusername/Library/Caches/deno/dep_analysis_cache_v2...
DEBUG RS - deno::cache::cache_db:168 - Opening cache /Users/myusername/Library/Caches/deno/node_analysis_cache_v2...
DEBUG RS - deno::cache::cache_db:168 - Opening cache /Users/myusername/Library/Caches/deno/v8_code_cache_v2...
DEBUG RS - deno::npm::managed::resolution:282 - Running npm resolution.
DEBUG RS - hyper_util::client::legacy::connect::dns:122 - resolving host="packages.mycompany.com"
DEBUG RS - hyper_util::client::legacy::connect::http:643 - connecting to 123.123.123.123:443
DEBUG RS - hyper_util::client::legacy::connect::http:646 - connected to 456.456.456.456:443
DEBUG RS - h2::client:1281 - binding client connection
DEBUG RS - h2::client:1286 - client connection bound
DEBUG RS - h2::codec::framed_write:213 - send frame=Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384, max_header_list_size: 16384 }
DEBUG RS - h2::proto::connection:138 - Connection; peer=Client
DEBUG RS - hyper_util::client::legacy::pool:396 - pooling idle connection for ("https", packages.mycompany.com)
DEBUG RS - h2::codec::framed_write:213 - send frame=WindowUpdate { stream_id: StreamId(0), size_increment: 5177345 }
DEBUG RS - h2::codec::framed_write:213 - send frame=Headers { stream_id: StreamId(1), flags: (0x5: END_HEADERS | END_STREAM) }
DEBUG RS - h2::codec::framed_read:405 - received frame=Settings { flags: (0x0), max_concurrent_streams: 128, initial_window_size: 65536, max_frame_size: 16777215 }
DEBUG RS - h2::codec::framed_write:213 - send frame=Settings { flags: (0x1: ACK) }
DEBUG RS - h2::codec::framed_read:405 - received frame=WindowUpdate { stream_id: StreamId(0), size_increment: 2147418112 }
DEBUG RS - h2::codec::framed_read:405 - received frame=Settings { flags: (0x1: ACK) }
DEBUG RS - h2::proto::settings:56 - received settings ACK; applying Settings { flags: (0x0), enable_push: 0, initial_window_size: 2097152, max_frame_size: 16384, max_header_list_size: 16384 }
DEBUG RS - h2::codec::framed_read:405 - received frame=Headers { stream_id: StreamId(1), flags: (0x4: END_HEADERS) }
DEBUG RS - h2::codec::framed_read:405 - received frame=Data { stream_id: StreamId(1) }
DEBUG RS - h2::codec::framed_read:405 - received frame=Data { stream_id: StreamId(1), flags: (0x1: END_STREAM) }
DEBUG RS - h2::codec::framed_write:213 - send frame=GoAway { error_code: NO_ERROR, last_stream_id: StreamId(0) }
DEBUG RS - h2::proto::connection:428 - Connection::poll; connection error error=GoAway(b"", NO_ERROR, Library)
error: Error getting response at https://packages.mycompany.com/artifactory/api/npm/npm-remote/@angular/cli%25C2%25A0 for package "@angular/cli%C2%A0": Bad response: 401

{
  "errors" : [ {
    "status" : 401,
    "message" : "Bad credentials"
  } ]
}

Stack backtrace:
   0: std::backtrace::Backtrace::capture
   1: anyhow::error::<impl core::convert::From<E> for anyhow::Error>::from
   2: deno::npm::managed::ManagedCliNpmResolver::add_package_reqs_raw::{{closure}}
   3: deno::npm::managed::ManagedCliNpmResolver::add_package_reqs::{{closure}}
   4: deno::worker::CliMainWorkerFactory::create_custom_worker::{{closure}}
   5: deno::worker::CliMainWorkerFactory::create_main_worker::{{closure}}
   6: deno::tools::run::run_script::{{closure}}
   7: deno::spawn_subcommand::{{closure}}
   8: <deno_unsync::tokio::task::MaskFutureAsSend<F> as core::future::future::Future>::poll
   9: tokio::runtime::task::raw::poll
  10: deno::main
  11: std::sys_common::backtrace::__rust_begin_short_backtrace
  12: _main
tribal lotus
#

Do you have a single npmrc file or multiple files?

civic peak
tribal lotus
#

Deno only looks up in your project dir and falls back to home dir

#

But it doesn't merge them like npm does

civic peak
#

when running the deno scripts, i was in ~/Documents/deno-scripts, and the only .npmrc between there and my home directory is the one in my home directory (which i shared above)

tribal lotus
#

Okay, thanks. Could I ask you to open an issue in GH? It's definitely a bug and I'm OOO today and i don't want it to get lost

civic peak
#

ahhh i forgot the global one. i don't think it's that but lets see

worldly hazel
civic peak
#

sorry will try make in a bit 🙂

i ran npm config ls -l , which to my understanding, prints the fully resolved config for npm (along with the file/place it came from).
i attached the result after replacing my username with myusername and my company with mycompany (nothing else changed)

i also ran
yarn config --json (and converted the newline-delimited json to a json array) and did the same replacements and uploaded that

#

not sure if they somehow help at all but i can make a bug report soon. if those give away the issue tho then please let me know 🙂

civic peak
cinder fox
#

I'm having a similar 401 issue with a private registry hosted on Azure DevOps - {"$id":"1","innerException":null,"message":"TF400813: The user 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa' is not authorized to access this resource.","typeName":"Microsoft.TeamFoundation.Framework.Server.UnauthorizedRequestException, Microsoft.TeamFoundation.Framework.Server","typeKey":"UnauthorizedRequestException","errorCode":0,"eventId":3000}

With the error message it returns it appears as though the credentials defined aren't properly being passed?

#

(I'm defining username and _password in the project .npmrc, npm installs without issue)

tribal lotus
#

@cinder fox can you give more details? Where do you have .npmrc file? Do you use multiple files? Ie. One in your project and the other in your home dir?

cinder fox
#

Hi, just a single .npmrc in project root (same dir as project.json)

tribal lotus
#

Then it should definitely work 😦 opening an issue with as many details as possible would be help - obviously without sharing any private information

#

We'll look into it this week

cinder fox
#

Should I add to the issue above or open a new one?

tribal lotus
#

Either one works!