Reputation: 6593
I have a Rails 7 app that is trying to use the @walletconnect/web3-provider
npm package. After running ./bin/importmap pin @walletconnect/[email protected]
, a bunch of JS modules get pinned in importmap.rb
:
pin "@walletconnect/web3-provider", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/browser-utils", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/client", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/core", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/crypto", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/browser/index.js"
pin "@walletconnect/encoding", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/environment", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/cjs/index.js"
pin "@walletconnect/http-connection", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/iso-crypto", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/jsonrpc-types", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/jsonrpc-utils", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/qrcode-modal", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/cjs/index.js"
pin "@walletconnect/randombytes", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/browser/index.js"
pin "@walletconnect/safe-json", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/socket-transport", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/utils", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/esm/index.js"
pin "@walletconnect/window-getters", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/cjs/index.js"
pin "@walletconnect/window-metadata", to: "https://ga.jspm.io/npm:@walletconnect/[email protected]/dist/cjs/index.js"
pin "bn.js", to: "https://ga.jspm.io/npm:[email protected]/lib/bn.js"
pin "buffer", to: "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/buffer.js"
pin "cookiejar", to: "https://ga.jspm.io/npm:[email protected]/cookiejar.js"
pin "copy-to-clipboard", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "decode-uri-component", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "detect-browser", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "dijkstrajs", to: "https://ga.jspm.io/npm:[email protected]/dijkstra.js"
pin "eventemitter3", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "http", to: "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/http.js"
pin "https", to: "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/https.js"
pin "is-typedarray", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "isarray", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "js-sha3", to: "https://ga.jspm.io/npm:[email protected]/src/sha3.js"
pin "os", to: "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/os.js"
pin "preact", to: "https://ga.jspm.io/npm:[email protected]/dist/preact.module.js"
pin "preact/compat", to: "https://ga.jspm.io/npm:[email protected]/compat/dist/compat.module.js"
pin "preact/hooks", to: "https://ga.jspm.io/npm:[email protected]/hooks/dist/hooks.module.js"
pin "process", to: "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/process-production.js"
pin "qrcode", to: "https://ga.jspm.io/npm:[email protected]/lib/browser.js"
pin "qrcode/lib/utils/buffer.js", to: "https://ga.jspm.io/npm:[email protected]/lib/utils/typedarray-buffer.js"
pin "query-string", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "split-on-first", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "strict-uri-encode", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "toggle-selection", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "typedarray-to-buffer", to: "https://ga.jspm.io/npm:[email protected]/index.js"
pin "url", to: "https://ga.jspm.io/npm:@jspm/[email protected]/nodelibs/browser/url.js"
pin "xhr2-cookies", to: "https://ga.jspm.io/npm:[email protected]/dist/index.js"
I import the package in application.js
:
import "@walletconnect/web3-provider"
And then I try to import a specific module in my custom JS file (which is also imported in application.js
):
import WalletConnectProvider from "@walletconnect/web3-provider";
When I start the server and visit the site in the browser, it shows following error:
Uncaught SyntaxError: The requested module 'js-sha3' does not provide an export named 'keccak_256' (at index.js:1:189)
I don't understand why this error is happening. When I look at the js-sha3 repo, I see that keccak_256
is exported here. So, why is this error happening?
Thanks!
Upvotes: 1
Views: 1310
Reputation: 2956
What you linked to is a TS type definition. It has no runtime effect. It's just there for type hints in your editor.
That package is only distributed as CJS -- there are no exports, and you cannot use it without a bundler. Using it directly in the browser (as you attempt to) will not work.
Upvotes: 1