Cannot read properties of null (reading 'byteLength')

I keep getting this error in my script but I can't figure out the cause of it.
TypeError: Cannot read properties of null (reading 'byteLength')
at Object.pull (C:\Users\*\Documents\Bot\node_modules\undici\lib\web\fetch\body.js:66:20)
at invokePromiseCallback (node:internal/webstreams/util:172:10)
at Object.<anonymous> (node:internal/webstreams/util:177:23)
at readableByteStreamControllerCallPullIfNeeded (node:internal/webstreams/readablestream:3145:24)
at readableByteStreamControllerPullSteps (node:internal/webstreams/readablestream:3254:3)
at [kPull] (node:internal/webstreams/readablestream:1201:5)
at readableStreamDefaultReaderRead (node:internal/webstreams/readablestream:2269:39)
at nextSteps (node:internal/webstreams/readablestream:493:7)
at async writeIterable (C:\Users\*\Documents\Bot\node_modules\undici\lib\dispatcher\client-h1.js:1439:22)
TypeError: Cannot read properties of null (reading 'byteLength')
at Object.pull (C:\Users\*\Documents\Bot\node_modules\undici\lib\web\fetch\body.js:66:20)
at invokePromiseCallback (node:internal/webstreams/util:172:10)
at Object.<anonymous> (node:internal/webstreams/util:177:23)
at readableByteStreamControllerCallPullIfNeeded (node:internal/webstreams/readablestream:3145:24)
at readableByteStreamControllerPullSteps (node:internal/webstreams/readablestream:3254:3)
at [kPull] (node:internal/webstreams/readablestream:1201:5)
at readableStreamDefaultReaderRead (node:internal/webstreams/readablestream:2269:39)
at nextSteps (node:internal/webstreams/readablestream:493:7)
at async writeIterable (C:\Users\*\Documents\Bot\node_modules\undici\lib\dispatcher\client-h1.js:1439:22)
Short code snippet:
if (interaction.commandName === "cardtest") {
const canvas = createCanvas(700, 250);
const context = canvas.getContext('2d');

const backgroundPath = path.join(__dirname, "assets", "contribution-card-background.png")
const background = await readFile(backgroundPath);
const backgroundImage = new Image();
backgroundImage.src = background;
context.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);

const attachment = new AttachmentBuilder(canvas.toBuffer('image/png'), { name: 'profile-image.png' });
console.log(attachment)

interaction.reply({ files: [attachment] });
}
if (interaction.commandName === "cardtest") {
const canvas = createCanvas(700, 250);
const context = canvas.getContext('2d');

const backgroundPath = path.join(__dirname, "assets", "contribution-card-background.png")
const background = await readFile(backgroundPath);
const backgroundImage = new Image();
backgroundImage.src = background;
context.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);

const attachment = new AttachmentBuilder(canvas.toBuffer('image/png'), { name: 'profile-image.png' });
console.log(attachment)

interaction.reply({ files: [attachment] });
}
16 Replies
d.js toolkit
d.js toolkit•5d ago
NyR
NyR•5d ago
What is your discord.js version? Can you do npm ls discord.js?
thom463s
thom463sOP•5d ago
14.22.1
NyR
NyR•5d ago
Can you do, npm ls @discordjs/rest and show me the output?
thom463s
thom463sOP•5d ago
No description
NyR
NyR•5d ago
Weird, this was fixed. I'm not sure if the fix was backported tho
thom463s
thom463sOP•5d ago
i've been stuck at this problem for a few hours now, I might just scrap the entire thing for the time being
NyR
NyR•5d ago
The original issue was from undici which labeled it as non-issue. There was a fix from d.js side for dev in this pr https://github.com/discordjs/discord.js/pull/11015
thom463s
thom463sOP•5d ago
that sucks not really sure where to go from there
NyR
NyR•5d ago
Do you have undici installed separately?
thom463s
thom463sOP•5d ago
yeah
NyR
NyR•5d ago
Then that's likely the issue, the version affected with the bug is not used by d.js, so you installing the latest version could be the issue here
thom463s
thom463sOP•5d ago
let me try and uninstall
thom463s
thom463sOP•5d ago
the built attachment exists I think, but the image is never sent via reply
No description
thom463s
thom463sOP•5d ago
the error doesnt show up anymore either theres nothing wrong with this is there
const attachment = new AttachmentBuilder(canvas.toBuffer('image/png'), { name: 'profile-image.png' });
return interaction.reply({ files: [attachment] })
const attachment = new AttachmentBuilder(canvas.toBuffer('image/png'), { name: 'profile-image.png' });
return interaction.reply({ files: [attachment] })
so things work now because I also had noblox.js installed which was interferring with the discord.js' undici but now my problem is how I can keep both packages without both versions of undici interfering with eachother

Did you find this page helpful?