首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Ipfs-http-client在我的react应用程序中不是公认的模块

Ipfs-http-client在我的react应用程序中不是公认的模块
EN

Stack Overflow用户
提问于 2021-04-18 11:10:27
回答 2查看 1K关注 0票数 4

我试图使用我的反应应用程序内的ipfs包,但它不会识别模块时,我运行。

代码语言:javascript
复制
sudo npm start

我将模块安装在

代码语言:javascript
复制
 sudo npm install -g --unsafe-perm ipfs-http-client

这将使用以下输出安装

代码语言:javascript
复制
> iso-constants@0.1.2 install /home/a/Documents/c/d1/dapp1/Dapp/client/node_modules/iso-constants
> node build.js > index.browser.js


> secp256k1@4.0.2 install /home/a/Documents/c/d1/dapp1/Dapp/client/node_modules/libp2p-crypto/node_modules/secp256k1
> node-gyp-build || exit 0


> ursa-optional@0.10.2 install /home/a/Documents/c/d1/dapp1/Dapp/client/node_modules/ursa-optional
> node rebuild.js


> protobufjs@6.10.2 postinstall /home/a/Documents/c/d1/dapp1/Dapp/client/node_modules/protobufjs
> node scripts/postinstall

npm WARN bootstrap@4.5.0 requires a peer of jquery@1.9.1 - 3 but none is installed. You must install peer dependencies yourself.
npm WARN bootstrap@4.5.0 requires a peer of popper.js@^1.16.0 but none is installed. You must install peer dependencies yourself.
npm WARN tsutils@3.17.1 requires a peer of typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/babel/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/jest-haste-map/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

+ ipfs-http-client@49.0.4
added 137 packages from 293 contributors, removed 64 packages, updated 15 packages, moved 8 packages and audited 2367 packages in 118.569s

这就是我所犯的错误

代码语言:javascript
复制
./src/components/ipfs/fileUpload.js
Module not found: Can't resolve 'ipfs-api' in '/home/a/Documents/c/d1/dapp1/Dapp/client/src/components/ipfs'

这是组件

代码语言:javascript
复制
import React, { Component, useEffect, useState } from "react";
const ipfsAPI = require('ipfs-api')

// connect to the default API address http://localhost:5001


const UploadImage = () => {

  const [request, setRequest] = useState({});
const ipfs = ipfsAPI

  const handleSubmit = async  (data) => {

    const { cid } = await ipfs.add(data)

  }

  return (
    <div>
      <form method="post" onSubmit={handleSubmit} enctype="multipart/form-data">
        <div>
          <label for="profile_pic">Choose file to upload</label>
          <input type="file" id="profile_pic" name="profile_pic"
                accept=".jpg, .jpeg">
          </input>
        </div>
        <div>
          <button>Submit</button>
        </div>
      </form>
    </div>
  )
}

export default UploadImage;

我使用的是节点版本v14.16.1和NPMVersion6.14.12,我也用-g全局安装了它,它也安装成功,但是当我运行start时也会出现同样的错误。

EN

回答 2

Stack Overflow用户

发布于 2022-06-13 17:30:03

包括一个特定版本的ipfs软件包,

喜欢

代码语言:javascript
复制
npm i ipfs-http-client@33.0.1
票数 2
EN

Stack Overflow用户

发布于 2022-11-07 13:34:01

我解决了这个问题

代码语言:javascript
复制
npm i ipfs-http-client@50.1.2 @babel/core --save
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/67147842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档