Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
`Duplex.from()` throws `The "iterable" argument must be an instance of Iterable. Received an instance of Object`

Im highly confused. The Duplex.from() method can take a object as src and creates fromt he object properties readable & writable a duplex stream:

converts readable and writable into Stream and then combines them into Duplex where the Duplex will write to the writable and read from the readable.

Why does my example not work?

const { PassThrough, Duplex } = require("stream");


const loopback = new PassThrough();


const duplex = Duplex.from({
    writable: loopback,
    readable: loopback
});


duplex.on("data", (chunk) => {
    console.log("Data on duplex", chunk)
});


duplex.write("Hello World");

My expected outcome is that the a duplex stream is created, and if so, that outputs the same i give as input. (Same as "echo", or plain passthrough stream)

Error message:

[nodemon] starting `node index.js`
internal/streams/from.js:32
    throw new ERR_INVALID_ARG_TYPE('iterable', ['Iterable'], iterable);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "iterable" argument must be an instance of Iterable. Received an instance of Object
    at new NodeError (internal/errors.js:322:7)
    at from (internal/streams/from.js:32:11)
    at Function.Readable.from (internal/streams/readable.js:1368:10)
    at Object.<anonymous> (/home/marc/projects/test-stream/index.js:7:23)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:75:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'ERR_INVALID_ARG_TYPE'
}

Can some one explain to my why i cant create a duplex stream from the a object?

Im a bit lost, since the docs say you can pass a object as argument, but the error message says "must be an instance of Iterable". As far as i know, a object is iterable. So whats the problem here?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Never mind, i found my mistake.

I was using a outdated node verison:

node -v
v14.19.0

I updated to node.js v16 via nodesource (https://github.com/nodesource/distributions#deb):

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

And it worked as expected.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!