rails icon indicating copy to clipboard operation
rails copied to clipboard

Rails & can't pin JS files from Unpkg

Open septerr opened this issue 1 year ago • 2 comments

Steps to reproduce

In a new Rails & app, try to pin a package from Unpkg CDN:

./bin/importmap pin @walletconnect/[email protected] --from unpkg

You get following response:

Couldn't find any packages in ["@walletconnect/[email protected]"] on unpkg

But the file does exist on unpkg: https://unpkg.com/@walletconnect/[email protected]/dist/umd/index.min.js

After adding some breakpoints in .rbenv/versions/3.1.0/lib/ruby/gems/3.1.0/gems/importmap-rails-1.1.5/lib/importmap/packager.rb, saw that the CDN post request and response are as follows:

Post URL:

<URI::HTTPS https://api.jspm.io/generate>

Post Body:

 "{\"install\":[\"@walletconnect/[email protected]\"],\"flattenScope\":true,\"env\":[\"browser\",\"module\",\"production\"],\"provider\":\"unpkg\"}"

Post Response:

<Net::HTTPUnauthorized 401 Unauthorized readbody=true>

Expected behavior

Expected the files from unpkg to be pinned.

Actual behavior

Misleading error that files don't exist on unpkg.

System configuration

Rails version: Rails 7.0.3.1

Ruby version: ruby 3.1.0p0 (2021-12-25 revision fb4df44d16) [arm64-darwin21]

septerr avatar Jul 30 '22 21:07 septerr

This sounds like an issue with the jspm api. I'll leave this open for a bit but an issue should probably be raised with them

skipkayhil avatar Aug 01 '22 04:08 skipkayhil

Replication script:

require "rails"
require "importmap-rails"
require "importmap/packager"
require "net-http-spy"
Net::HTTP.http_logger_options = { verbose: true, body: true, trace: true }

Importmap::Packager.new.import("@walletconnect/[email protected]", from: "unpkg")

Output:

opening connection to api.jspm.io:443...
opened
starting SSL for api.jspm.io:443...
SSL established, protocol: TLSv1.3, cipher: TLS_AES_256_GCM_SHA384
<- "POST /generate HTTP/1.1\r\nContent-Type: application/json\r\nAccept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3\r\nAccept: */*\r\nUser-Agent: Ruby\r\nHost: api.jspm.io\r\nContent-Length: 129\r\n\r\n"
<- "{\"install\":[\"@walletconnect/[email protected]\"],\"flattenScope\":true,\"env\":[\"browser\",\"module\",\"production\"],\"provider\":\"unpkg\"}"
-> "HTTP/1.1 401 Unauthorized\r\n"
-> "content-type: application/json\r\n"
-> "access-control-allow-origin: *\r\n"
-> "X-Cloud-Trace-Context: fe518e38c1b8c17b27ed023a4da94bd3\r\n"
-> "Date: Tue, 02 Aug 2022 18:07:27 GMT\r\n"
-> "Server: Google Frontend\r\n"
-> "Content-Length: 181\r\n"
-> "\r\n"
reading 181 bytes...
-> "{\"error\":\"Error: Module not found: https://unpkg.com/@walletconnect/[email protected]/dist/esm/operations imported from https://unpkg.com/@walletconnect/[email protected]/dist/esm/constants\"}"
read 181 bytes
Conn keep-alive

Second what @skipkayhil said - seems to be an issue on the unpkg side.

ghiculescu avatar Aug 02 '22 18:08 ghiculescu

This issue has been automatically marked as stale because it has not been commented on for at least three months. The resources of the Rails team are limited, and so we are asking for your help. If you can still reproduce this error on the 7-0-stable branch or on main, please reply with all of the information you have about it in order to keep the issue open. Thank you for all your contributions.

rails-bot[bot] avatar Oct 31 '22 18:10 rails-bot[bot]