HewloThere
HewloThere2d ago

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

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"
} ]
}
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';
import { thing } from 'npm:literally-anything';
deno run -A npm:@angular/cli
deno run -A npm:@angular/cli
i'll add debug logs and configs in the following messages
13 Replies
HewloThere
HewloThere2d ago
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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//packages.mycompany.com/api/npm/npm-remote/:always-auth=true
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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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=myusername@mycompany.com
//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
~ 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
HewloThere
HewloThere2d ago
here's an anonymized npm config list --json (apparently it's too long to copy)
bartlomieju
bartlomieju2d ago
Do you have a single npmrc file or multiple files?
HewloThere
HewloThere2d ago
afaik it only looks in 1 place? but if you can let me know where to look (apart from my home directory, because the one i shared is the one from my home dir) then i'm happy to share
bartlomieju
bartlomieju2d ago
Deno only looks up in your project dir and falls back to home dir But it doesn't merge them like npm does
HewloThere
HewloThere2d ago
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)
bartlomieju
bartlomieju2d ago
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
HewloThere
HewloThere2d ago
ahhh i forgot the global one. i don't think it's that but lets see
lcasdev
lcasdev2d ago
GitHub
Build software better, together
GitHub is where people build software. More than 100 million people use GitHub to discover, fork, and contribute to over 420 million projects.
From An unknown user
From An unknown user
From An unknown user
HewloThere
HewloThere2d ago
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
HewloThere
HewloThere2d ago
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 🙂
HewloThere
HewloThere2d ago
sorry for delay, i posted it here: https://github.com/denoland/deno/issues/26033
GitHub
401 Unauthorized when trying to import with npm: specifier · Issu...
Directed here from this Discord thread: Deno > #help > deno gives 401 unauthorized for imports with an npm: specifier, but npm, yarn and pnpm all work Tested Deno Versions (all same result): ...