ipfs / js-ipfs

IPFS implementation in JavaScript
https://js.ipfs.tech
Other
7.43k stars 1.25k forks source link

TypeError: RequestInit: duplex option is required when sending a body. #4276

Closed Raman-Raje closed 1 year ago

Raman-Raje commented 1 year ago

Hi, I was working with ipfs-http-client version ^59.0.0. Everything was working fine, and I did some updates through brew, and Node got updated to V19. Previously I was on V18.13.0

Now the code is giving above mentioned error while performing ipfs.add operation. For other ipfs operations, everything is working fine. I did downgrade to node V18.13.0, but the issue is still there. I am not sure what wrong i am doing.

I am using Mac OS. Here is the code to reproduce the issue...

const ipfs = create({
    host: 'ipfs.infura.io',
    port: 5001,
    protocol: 'https',
    headers: {
        authorization: auth,
    },
});

const filepath = "./github.png";

fs.readFile(filepath, async (err , data) => {
    if (err){
        console.error(err);
    }
    const filename = filepath.split("/").pop();
    const result = await ipfs.add({path:filename,content:Buffer.from(data)});
    console.log(result);
}); 

Here is the error log :-

TypeError: RequestInit: duplex option is required when sending a body.
    at Object.fetch (node:internal/deps/undici/undici:14062:11)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Client.fetch (/Users/raman/Desktop/ipfs/ipfsNode/node_modules/ipfs-utils/src/http.js:132:22)
    at async addAll (file:///Users/raman/Desktop/ipfs/ipfsNode/node_modules/ipfs-http-client/src/add-all.js:36:17)
    at async last (file:///Users/raman/Desktop/ipfs/ipfsNode/node_modules/it-last/dist/src/index.js:7:22)
    at async Object.add (file:///Users/raman/Desktop/ipfs/ipfsNode/node_modules/ipfs-http-client/src/add.js:22:14)
welcome[bot] commented 1 year ago

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

Finally, remember to use https://discuss.ipfs.io if you just need general support.

Vectorrent commented 1 year ago

I am seeing the same problem. I tried a bunch of old versions, and they all seem to do the same thing. Here's the code:

import { create } from 'ipfs-http-client'

const ipfs = create({ url: '/ip4/127.0.0.1/tcp/5001' })
const { cid } = await ipfs.add('Hello world!')
console.log(cid)

And here's the output:

> node root.js

node:internal/deps/undici/undici:14062
    Error.captureStackTrace(err, this);
          ^

TypeError: RequestInit: duplex option is required when sending a body.
    at Object.fetch (node:internal/deps/undici/undici:14062:11)
    at async Client.fetch (/home/crow/Repos/src/node_modules/ipfs-utils/src/http.js:132:22)
    at async addAll (file:///home/crow/Repos/src/node_modules/ipfs-http-client/src/add-all.js:36:17)
    at async last (file:///home/crow/Repos/src/node_modules/it-last/dist/src/index.js:7:22)
    at async Object.add (file:///home/crow/Repos/src/node_modules/ipfs-http-client/src/add.js:22:14)
    at async file:///home/crow/Repos/src/root.js:10:17

Node.js v19.3.0
miladezzat commented 1 year ago

any update for this issue

Raman-Raje commented 1 year ago

I have found the solution. In my case, my node version got updated. Reverted it back to V16. Its working fine for me

lucas-sdl commented 1 year ago

What version node are you on? I'm hitting this error on 16.17.1

Raman-Raje commented 1 year ago

I am on V16.15.1. Try This one. Best Luck

miladezzat commented 1 year ago

I am switch to v18.12.1 and it works fine

dvncan commented 1 year ago

^ditto.. I didnt specify my node version past 18.x.x when deploying to heroku where they had recently changed default from 18.12 -> 18.13 which seems to break ipfs-https-client

Raman-Raje commented 1 year ago

I believe its resolved now. Closing the issue

SilvioGuedes commented 1 year ago

I believe its resolved now. Closing the issue

The problem is still happening:

TypeError: RequestInit: duplex option is required when sending a body.

NodeJS v18.15.0 IPFS (Kubo) v0.19.1 Windows 10

ejim11 commented 1 year ago

TypeError: RequestInit: duplex option is required when sending a body.

This issue is still happening. Please how can I resolve it?