Cannot read properties of null (reading 'byteLength') with AttachmentBuilder & @napi-rs/canvas

Moving my question from the djs help channel to here. currently running into an issue when attempting to edit an interaction reply with a buffer image created using napi-rs/canvas
const captcha = await buildCaptcha(correct);

const reply = await interaction.editReply({
embeds: [{
color: Colours.Primary,
description: 'To process your vote, please select the button with the right answer',
image: {
url: 'attachment://guilds-captcha.png'
}
}],
files: [new AttachmentBuilder(captcha, { name: 'guilds-captcha.png' })],
components: [{
type: ComponentType.ActionRow,
components: words.map((word, index) => ({
type: ComponentType.Button,
style: ButtonStyle.Secondary,
label: word,
custom_id: `captcha-${index}`
}))
}]
});
const captcha = await buildCaptcha(correct);

const reply = await interaction.editReply({
embeds: [{
color: Colours.Primary,
description: 'To process your vote, please select the button with the right answer',
image: {
url: 'attachment://guilds-captcha.png'
}
}],
files: [new AttachmentBuilder(captcha, { name: 'guilds-captcha.png' })],
components: [{
type: ComponentType.ActionRow,
components: words.map((word, index) => ({
type: ComponentType.Button,
style: ButtonStyle.Secondary,
label: word,
custom_id: `captcha-${index}`
}))
}]
});
This is the code which creates and sends the image. Commenting out the files property prevents the error, though of course prevents the image from being sent.
TypeError: Cannot read properties of null (reading 'byteLength')
at Object.pull (C:\...\node_modules\undici\lib\web\fetch\body.js:63:20)
at ensureIsPromise (node:internal/webstreams/util:185:19)
at readableByteStreamControllerCallPullIfNeeded (node:internal/webstreams/readablestream:3099:5)
at readableByteStreamControllerPullSteps (node:internal/webstreams/readablestream:3207:3)
at [kPull] (node:internal/webstreams/readablestream:1197:5)
at readableStreamDefaultReaderRead (node:internal/webstreams/readablestream:2243:39)
at nextSteps (node:internal/webstreams/readablestream:507:7)
at async writeIterable (C:\...\node_modules\undici\lib\dispatcher\client-h1.js:1437:22)
TypeError: Cannot read properties of null (reading 'byteLength')
at Object.pull (C:\...\node_modules\undici\lib\web\fetch\body.js:63:20)
at ensureIsPromise (node:internal/webstreams/util:185:19)
at readableByteStreamControllerCallPullIfNeeded (node:internal/webstreams/readablestream:3099:5)
at readableByteStreamControllerPullSteps (node:internal/webstreams/readablestream:3207:3)
at [kPull] (node:internal/webstreams/readablestream:1197:5)
at readableStreamDefaultReaderRead (node:internal/webstreams/readablestream:2243:39)
at nextSteps (node:internal/webstreams/readablestream:507:7)
at async writeIterable (C:\...\node_modules\undici\lib\dispatcher\client-h1.js:1437:22)
I've logged captcha and it's definitely a buffer, and I've also stored it as a file, and it's definitely a working image d.js version: v14.19.3
No description
8 Replies
d.js toolkit
d.js toolkit3d ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
Zerls
ZerlsOP3d ago
I've also logged this:
console.log('Buffer.isBuffer: ', Buffer.isBuffer(captcha), captcha.byteLength);
// Buffer.isBuffer: true 418165
console.log('Buffer.isBuffer: ', Buffer.isBuffer(captcha), captcha.byteLength);
// Buffer.isBuffer: true 418165
duck
duck3d ago
could you also share the output from npm ls undici?
Zerls
ZerlsOP3d ago
[email protected] C:\...\guilds
├─┬ @elastic/[email protected]
│ └─┬ @elastic/[email protected]
│ └── [email protected]
├─┬ @discordjs/[email protected]
│ └── [email protected]
[email protected] C:\...\guilds
├─┬ @elastic/[email protected]
│ └─┬ @elastic/[email protected]
│ └── [email protected]
├─┬ @discordjs/[email protected]
│ └── [email protected]
duck
duck3d ago
yeah for some reason @discordjs/rest seems to be using that installation of undici v7 the lines in your stack trace match up with v7 as opposed to v6, and I can only reproduce this by overriding the pinned version in /rest
Zerls
ZerlsOP2d ago
not sure why my other bot (which currently runs v14.19.1 but so did this one until i updated earlier) doesnt run into this same issue. this is the other bot's output for npm ls undici:
[email protected] C:\...\guilds
├─┬ @elastic/[email protected]
│ └─┬ @elastic/[email protected]
│ └── [email protected]
│ ├─┬ @discordjs/[email protected]
│ │ └── [email protected] deduped
│ └── [email protected]
└─┬ @top-gg/[email protected]
[email protected] C:\...\guilds
├─┬ @elastic/[email protected]
│ └─┬ @elastic/[email protected]
│ └── [email protected]
│ ├─┬ @discordjs/[email protected]
│ │ └── [email protected] deduped
│ └── [email protected]
└─┬ @top-gg/[email protected]
only solution i've been able to think of is just downgrading my elastic search version to one which uses v6. Have you got any ideas? @duck
duck
duck2d ago
frankly, I usually assume issues like this are caused at a package manager level if you haven't tried it already, a fresh install of deps may help
Zerls
ZerlsOP2d ago
i had tried that multiple times. i've managed to fix it now though, something to do with importing a file which exported an elastic search document. not sure how it occured considering this file is exported on both cluster and manager side but it's fixed now so thats good enough for me 😅

Did you find this page helpful?