【问题标题】:TypeError: fs.stat is not a function (IPFS JS)TypeError:fs.​​stat 不是函数(IPFS JS)
【发布时间】:2021-08-26 04:20:33
【问题描述】:

我正在根据教程学习​​ ipfs js,但是当我学习时,我在终端中输入 node main.js 时遇到问题,如下所示:

/Users/username/Documents/coding/ipfs-test/node_modules/lock-me/src/unix.js:9
    (cb) => fs.stat(name, (err, stats) => {
               ^

TypeError: fs.stat is not a function
    at waterfall (/Users/username/Documents/coding/ipfs-test/node_modules/lock-me/src/unix.js:9:16)
    at nextTask (/Users/username/Documents/coding/ipfs-test/node_modules/async/waterfall.js:16:14)
    at exports.default (/Users/username/Documents/coding/ipfs-test/node_modules/async/waterfall.js:26:5)
    at unixLock (/Users/username/Documents/coding/ipfs-test/node_modules/lock-me/src/unix.js:8:3)
    at lock (/Users/username/Documents/coding/ipfs-test/node_modules/lock-me/src/index.js:53:5)
    at Object.exports.lock (/Users/username/Documents/coding/ipfs-test/node_modules/ipfs-repo/src/lock.js:23:3)
    at IpfsRepo._openLock (/Users/username/Documents/coding/ipfs-test/node_modules/ipfs-repo/src/index.js:168:18)
    at waterfall (/Users/username/Documents/coding/ipfs-test/node_modules/ipfs-repo/src/index.js:96:20)

这是用 main.js 编写的代码:

const IPFS = require('ipfs');
console.log("Imported IPFS");
const mynode = new IPFS();
console.log("Starting Server");

mynode.on('ready', async () => {
    console.log("Server Started");
    const version = await mynode.version();
    console.log(version.version);
});

信息: 我正在使用节点 js 版本 8.13.0, 我使用的 IPFS JS 版本是 0.32.3, 使用 OS MacOS Bigsur 11.4

这个问题有解决办法吗?谢谢^^

【问题讨论】:

    标签: javascript node.js ipfs js-ipfs


    【解决方案1】:

    我不确定您正在遵循什么教程,但这里有一个使用 js-ipfs 0.55.3 让您的代码运行的最小示例:

    const IPFS = require('ipfs');
    console.log("Imported IPFS");
    
    async function run() {
        console.log("Starting Server");
        const mynode = await IPFS.create();
    
        console.log("Server Started");
        const version = await mynode.version();
        console.log(version.version);
    }
    
    run();
    

    【讨论】:

    • 感谢您的帮助,您提供的方法如果使用最新的节点 js 和 ipfs js 版本 0.55.3 运行,效果真的很好。但是,对于 Node js 版本 8.13.0 和 IPFS JS 版本 0.32.3,它不起作用。出现这样的错误:Imported IPFS Starting Server (node:25730) UnhandledPromiseRejectionWarning: TypeError: IPFS.create is not a function 有解决办法吗?
    • @AdamFaturahman 有什么办法可以避免使用这种旧版本的 js-ipfs?很难支持很多旧版本的软件(尤其是 1.0 之前的版本),我通常建议人们尽可能使用最新版本的 js-ipfs。请让我知道这是否不可能,以及为什么:)。
    猜你喜欢
    • 2020-11-16
    • 2020-04-26
    • 2020-03-01
    • 2020-02-12
    • 2021-09-24
    • 1970-01-01
    • 2022-06-30
    • 2021-01-10
    • 2016-10-03
    相关资源
    最近更新 更多