'How to resolve TypeError: Cannot convert "null" to int
Error:
TypeError: Cannot convert "null" to int.
function play(connection, message){
var server = servers[message.guild.id];
server.dispatcher = connection.play(ytdl(server.queue[0], {filter: "audioonly"}));
server.queue.shift();
server.dispatcher.on("end", function(){
if(server.queue[0]){
play(connection, message);
}else {
connection.disconnect();
}
})
}
The error message I'm getting from the tester is:
TypeError: Cannot convert "null" to int
TypeError: Cannot convert "null" to int
Error: "abort(TypeError: Cannot convert "null" to int). Build with -s ASSERTIONS=1 for more info."
at (anonymous) (file:///c:/Users/pc/Documents/Discord%20Bot/node_modules/opusscript/build/opusscript_native_wasm.js:8:1741)
at emit (events.js:311:19)
I'm begging you, please help me. Thanks.
Solution 1:[1]
I may have a solution for your problem!
UPDATE:
Following this answer and my bug report, prism-media released a fixed version. Thank you for such a quick solution! Keeping the text below just as a reference.
TL;DR
Find Opus.js in node_modules folder and go to line 55. You should see the following:
return this.encoder.encode(buffer, Opus.name === 'opusscript' ? null : this._options.frameSize);
CHANGE IT TO:
return this.encoder.encode(buffer, this._options.frameSize);
Then delete the same part at line 59.
Explanation
The exception is thrown in
toWireTypein opusscript_native_wasm.js which expects its second argument to be an int, but it gets anull. Hence, the exception.Tracing it back,
toWireTypeis called byOpusScriptHandler.encodefor all its arguments.Those four arguments come from
OpusScript.prototype.encodeinopusscript.js:69. The last argument causing the trouble (beingnull) is `frameSize.The
encodefunction is called fromOpus.js:55in prism-media which is a different module.
return this.encoder.encode(buffer, Opus.name === 'opusscript' ? null : this._options.frameSize);
There it is, the null causing all the trouble. So the exception is in fact not a fault of the opusscript package.
Long-term solutions
I reported the bug to the module owner, hopefully it gets fixed. Update: it has been fixed within a few hours! :)
Alternative solution
Using a custom loader should also work fine. It's still a hack, but more persistent :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
