Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ BUG ] TypeError [ERR_INVALID_ARG_TYPE] #317

Closed
waleedarshad-vf opened this issue Jun 24, 2020 · 9 comments
Closed

[ BUG ] TypeError [ERR_INVALID_ARG_TYPE] #317

waleedarshad-vf opened this issue Jun 24, 2020 · 9 comments

Comments

@waleedarshad-vf
Copy link

waleedarshad-vf commented Jun 24, 2020

Got this error while calling: streamToPromise(sms).then(buffer => console.log(buffer.toString()))

TypeError [ERR_INVALID_ARG_TYPE]: The "list" argument must be one of type Array, Buffer, or Uint8Array. Received type undefined

@waleedarshad-vf
Copy link
Author

waleedarshad-vf commented Jun 24, 2020

stack

buffer.js:458
    throw new ERR_INVALID_ARG_TYPE(
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "list" argument must be one of type Array, Buffer, or Uint8Array. Received type undefined
    at Function.concat (buffer.js:458:11)
    at Writable.stream.pipe.on.on (/Users/macbookpro/Documents/box/node_modules/sitemap/dist/lib/sitemap-stream.js:103:48)
    at Writable.emit (events.js:203:15)
    at Writable.EventEmitter.emit (domain.js:448:20)
    at finishMaybe (_stream_writable.js:646:14)
    at endWritable (_stream_writable.js:663:3)
    at Writable.end (_stream_writable.js:594:5)
    at SitemapAndIndexStream.onend (_stream_readable.js:671:10)
    at Object.onceWrapper (events.js:286:20)
    at SitemapAndIndexStream.emit (events.js:203:15)

@derduher
Copy link
Collaborator

Hi @waleedarshad-vf, just giving you a heads-up that I will look into this this weekend. Not ignoring you, just busy hunting for a new job.

@waleedarshad-vf
Copy link
Author

Thanks

@derduher
Copy link
Collaborator

@waleedarshad-vf I'm going to need more than a stacktrace to debug this. Please provide a minimal reproducible test case and the version of node you are on.

@waleedarshad-vf
Copy link
Author

@derduher
Node: v10.16.3

I just followed simple steps

  const sms = new SitemapAndIndexStream({
    limit: 10000, // defaults to 45k,  it will create a new sitemap file based upon limit
    getSitemapStream: i => {
      const sitemapStream = new SitemapStream({
        hostname: domain
      });
      const path = `./sitemap/sitemap-${i}.xml`;

       sitemapStream
        .pipe(fs.createWriteStream(resolve(path + ""))); // write it to sitemap-NUMBER.xml

        return [new URL(path, domain).toString(), sitemapStream];
     }
    });
    sms.pipe(fs.createWriteStream(resolve("./sitemap-index.xml")));

     let arrayOfSitemapItems = await getUrls();

    
     arrayOfSitemapItems.forEach(item => sms.write(item));
     sms.end();

     let xml = await streamToPromise(SMS)

     console.log("xml",xml);

@derduher
Copy link
Collaborator

derduher commented Jul 1, 2020

sms.end needs to be called after stream to promise. I suggest converting the await to a traditional promise. Otherwise you are closing the stream without having written anything out yet. It doesn't start pulling on the stream until streamToPromise is invoked as it has nowhere to write.

arrayOfSitemapItems.forEach(item => sms.write(item));
     

streamToPromise(sms).then(xml => console.log(xml))
sms.end();

@derduher
Copy link
Collaborator

derduher commented Jul 1, 2020

I'm going to try to improve the error message for this case and the documentation around streams in general.

@waleedarshad-vf
Copy link
Author

waleedarshad-vf commented Jul 1, 2020

Seems like in your testcase. you are closing before
I will follow your steps and let you know

const smis = new SitemapItemStream();
smis.write(testData);
smis.end();
expect((await streamToPromise(smis)).toString()).toBe(...

Link: https://github.com/ekalinin/sitemap.js/blob/master/tests/sitemap-item-stream.test.ts#L108

@derduher
Copy link
Collaborator

derduher commented Jul 1, 2020

Curious. I'm not sure why that worked.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants