簡體   English   中英

類型錯誤:fs.stat 不是 function (IPFS JS)

[英]TypeError: fs.stat is not a function (IPFS JS)

我正在根據教程學習 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);
});

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

這個問題有解決方案嗎? 謝謝^^

我不確定您正在遵循哪個教程,但這里有一個使用 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();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM