JS包不适用于Rails7importmap



我有一个Rails 7应用程序,它正在尝试使用@walletconnect/web3-providernpm包。运行./bin/importmap pin @walletconnect/web3-provider@1.7.5后,一堆JS模块被固定在importmap.rb:中

pin "@walletconnect/web3-provider", to: "https://ga.jspm.io/npm:@walletconnect/web3-provider@1.7.5/dist/esm/index.js"
pin "@walletconnect/browser-utils", to: "https://ga.jspm.io/npm:@walletconnect/browser-utils@1.7.8/dist/esm/index.js"
pin "@walletconnect/client", to: "https://ga.jspm.io/npm:@walletconnect/client@1.7.8/dist/esm/index.js"
pin "@walletconnect/core", to: "https://ga.jspm.io/npm:@walletconnect/core@1.7.8/dist/esm/index.js"
pin "@walletconnect/crypto", to: "https://ga.jspm.io/npm:@walletconnect/crypto@1.0.2/dist/esm/browser/index.js"
pin "@walletconnect/encoding", to: "https://ga.jspm.io/npm:@walletconnect/encoding@1.0.1/dist/esm/index.js"
pin "@walletconnect/environment", to: "https://ga.jspm.io/npm:@walletconnect/environment@1.0.0/dist/cjs/index.js"
pin "@walletconnect/http-connection", to: "https://ga.jspm.io/npm:@walletconnect/http-connection@1.7.8/dist/esm/index.js"
pin "@walletconnect/iso-crypto", to: "https://ga.jspm.io/npm:@walletconnect/iso-crypto@1.7.8/dist/esm/index.js"
pin "@walletconnect/jsonrpc-types", to: "https://ga.jspm.io/npm:@walletconnect/jsonrpc-types@1.0.1/dist/esm/index.js"
pin "@walletconnect/jsonrpc-utils", to: "https://ga.jspm.io/npm:@walletconnect/jsonrpc-utils@1.0.3/dist/esm/index.js"
pin "@walletconnect/qrcode-modal", to: "https://ga.jspm.io/npm:@walletconnect/qrcode-modal@1.7.8/dist/cjs/index.js"
pin "@walletconnect/randombytes", to: "https://ga.jspm.io/npm:@walletconnect/randombytes@1.0.2/dist/esm/browser/index.js"
pin "@walletconnect/safe-json", to: "https://ga.jspm.io/npm:@walletconnect/safe-json@1.0.0/dist/esm/index.js"
pin "@walletconnect/socket-transport", to: "https://ga.jspm.io/npm:@walletconnect/socket-transport@1.7.8/dist/esm/index.js"
pin "@walletconnect/utils", to: "https://ga.jspm.io/npm:@walletconnect/utils@1.7.8/dist/esm/index.js"
pin "@walletconnect/window-getters", to: "https://ga.jspm.io/npm:@walletconnect/window-getters@1.0.0/dist/cjs/index.js"
pin "@walletconnect/window-metadata", to: "https://ga.jspm.io/npm:@walletconnect/window-metadata@1.0.0/dist/cjs/index.js"
pin "bn.js", to: "https://ga.jspm.io/npm:bn.js@4.11.8/lib/bn.js"
pin "buffer", to: "https://ga.jspm.io/npm:@jspm/core@2.0.0-beta.24/nodelibs/browser/buffer.js"
pin "cookiejar", to: "https://ga.jspm.io/npm:cookiejar@2.1.3/cookiejar.js"
pin "copy-to-clipboard", to: "https://ga.jspm.io/npm:copy-to-clipboard@3.3.1/index.js"
pin "decode-uri-component", to: "https://ga.jspm.io/npm:decode-uri-component@0.2.0/index.js"
pin "detect-browser", to: "https://ga.jspm.io/npm:detect-browser@5.2.0/index.js"
pin "dijkstrajs", to: "https://ga.jspm.io/npm:dijkstrajs@1.0.2/dijkstra.js"
pin "eventemitter3", to: "https://ga.jspm.io/npm:eventemitter3@4.0.7/index.js"
pin "http", to: "https://ga.jspm.io/npm:@jspm/core@2.0.0-beta.24/nodelibs/browser/http.js"
pin "https", to: "https://ga.jspm.io/npm:@jspm/core@2.0.0-beta.24/nodelibs/browser/https.js"
pin "is-typedarray", to: "https://ga.jspm.io/npm:is-typedarray@1.0.0/index.js"
pin "isarray", to: "https://ga.jspm.io/npm:isarray@2.0.5/index.js"
pin "js-sha3", to: "https://ga.jspm.io/npm:js-sha3@0.8.0/src/sha3.js"
pin "os", to: "https://ga.jspm.io/npm:@jspm/core@2.0.0-beta.24/nodelibs/browser/os.js"
pin "preact", to: "https://ga.jspm.io/npm:preact@10.4.1/dist/preact.module.js"
pin "preact/compat", to: "https://ga.jspm.io/npm:preact@10.4.1/compat/dist/compat.module.js"
pin "preact/hooks", to: "https://ga.jspm.io/npm:preact@10.4.1/hooks/dist/hooks.module.js"
pin "process", to: "https://ga.jspm.io/npm:@jspm/core@2.0.0-beta.24/nodelibs/browser/process-production.js"
pin "qrcode", to: "https://ga.jspm.io/npm:qrcode@1.4.4/lib/browser.js"
pin "qrcode/lib/utils/buffer.js", to: "https://ga.jspm.io/npm:qrcode@1.4.4/lib/utils/typedarray-buffer.js"
pin "query-string", to: "https://ga.jspm.io/npm:query-string@6.13.5/index.js"
pin "split-on-first", to: "https://ga.jspm.io/npm:split-on-first@1.1.0/index.js"
pin "strict-uri-encode", to: "https://ga.jspm.io/npm:strict-uri-encode@2.0.0/index.js"
pin "toggle-selection", to: "https://ga.jspm.io/npm:toggle-selection@1.0.6/index.js"
pin "typedarray-to-buffer", to: "https://ga.jspm.io/npm:typedarray-to-buffer@3.1.5/index.js"
pin "url", to: "https://ga.jspm.io/npm:@jspm/core@2.0.0-beta.24/nodelibs/browser/url.js"
pin "xhr2-cookies", to: "https://ga.jspm.io/npm:xhr2-cookies@1.1.0/dist/index.js"

我在application.js:中导入包

import "@walletconnect/web3-provider"

然后我尝试在我的自定义JS文件中导入一个特定的模块(它也在application.js中导入(:

import WalletConnectProvider from "@walletconnect/web3-provider";

当我启动服务器并在浏览器中访问网站时,它显示以下错误:

Uncaught SyntaxError: The requested module 'js-sha3' does not provide an export named 'keccak_256' (at index.js:1:189)

我不明白为什么会发生这个错误。当我查看js-sha3 repo时,我看到这里导出了keccak_256。那么,为什么会出现这种错误呢?

谢谢!

您链接到的是TS类型定义。它没有运行时效果。它只是用于编辑器中的类型提示。

该包仅以CJS的形式分发——没有导出,没有bundler就无法使用它。直接在浏览器中使用它(当您尝试使用时(将不起作用。

相关内容

  • 没有找到相关文章

最新更新