我尝试在我的react应用程序中使用ipfs包,但是当我运行时它无法识别模块。
sudo npm start
我安装模块时
sudo npm install -g --unsafe-perm ipfs-http-client
这将安装以下输出
> 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
这是我得到的错误
./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'
这是组件
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和npm版本6.14.12,我还使用-g全局安装了它,它也安装成功,但当我运行sudo npm start时,我得到了相同的错误。
2条答案
按热度按时间zour9fqk1#
包括特定版本的IPFS包,
喜欢
62lalag42#
我用这个解决了