【问题标题】:Using Truffle-React + IPFS dependency issue使用 Truffle-React + IPFS 依赖问题
【发布时间】:2021-07-08 00:03:45
【问题描述】:

我是一名网络开发人员,拥有很多尝试学习 solidty + react 和 IFPS 的专家。我是这里的新手!将 IPFS 连接到我的 Truffle React 项目给我带来了问题。我只是在创建一个我可以从中学习的超级简单的示例,并且我遇到了一个依赖错误(我在想这就是发生的事情),我在网上找不到任何相关信息。我创建了其他solidy+react 应用程序,但这是我第一个涉及IPFS 的应用程序。

我已将 ifps 添加到我的工作松露项目中:

npm install --save ipfs-http-client

& 现在我正在尝试在我的 App.js 中实例化 ifps 对象,如下所示:

const { create: ipfsHttpClient } = require('ipfs-http-client');

添加此行会导致我没有看到其他人在网上谈论的错误。浏览器吐槽:

TypeError: TextDecoder is not a constructor ./node_modules/multiaddr/node_modules/multibase/src/util.js

C:/devroot/Solidity/ScriptureOfTheDay/client/node_modules/multiaddr/node_modules/multibase/src/util.js:7

   4 |       TextEncoder = _require.TextEncoder,

   5 |       TextDecoder = _require.TextDecoder;

   6 | 

>  7 | const textDecoder = new TextDecoder();

   8 | /**

   9 |  * @param {ArrayBufferView|ArrayBuffer} bytes

  10 |  * @returns {string}

这是来自 Chrome 控制台:

    **util.js:7 Uncaught TypeError: TextDecoder is not a constructor**
    at Object../node_modules/multiaddr/node_modules/multibase/src/util.js (util.js:7)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/multiaddr/node_modules/multibase/src/base.js (base.js:3)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/multiaddr/node_modules/multibase/src/constants.js (constants.js:5)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/multiaddr/node_modules/uint8arrays/to-string.js (to-string.js:3)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/multiaddr/src/ip.js (ip.js:5)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/multiaddr/src/convert.js (convert.js:3)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/multiaddr/src/codec.js (codec.js:3)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/multiaddr/src/index.js (index.js:3)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object../node_modules/ipfs-http-client/src/index.js (index.js:6)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Module.<anonymous> (App.js:7)
    at Module../src/App.js (App.js:96)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Module../src/index.js (index.css?e32c:37)
    at __webpack_require__ (bootstrap:785)
    at fn (bootstrap:150)
    at Object.0 (serviceWorker.js:135)
    at __webpack_require__ (bootstrap:785)
    at checkDeferredModules (bootstrap:45)
    at Array.webpackJsonpCallback [as push] (bootstrap:32)
    at main.chunk.js:1

有人有什么想法吗?我已经重新安装了 node_modules,从 stratch 开始 - 我只是一直在这里结束。 谢谢你的帮助, 克里斯B

【问题讨论】:

    标签: javascript node.js reactjs truffle ipfs


    【解决方案1】:

    我找到了答案:我不得不回到 ipfs-client-http v33.1.1。问题立刻解决了!该项目的起点是从 youtube 上一位老师的 github 链接下载的,视频是 2019 年。所以我需要回到 ipfs 的相对版本。

    注意 - 这里有另一个问题(2021 年 4 月),它是相同的,但使用 ipfs 本身而不是 ipfs-client-http。如果你遇到这个“TypeError: TextDecoder is not a constructor”——尝试回到旧版本的 ipfs。

    【讨论】:

      猜你喜欢
      • 2021-12-05
      • 1970-01-01
      • 2023-04-11
      • 2020-12-01
      • 2020-08-09
      • 2022-09-29
      • 2022-01-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多