You are generating the nonce incorrectly. Your 'sodium.randombytes_buf(i)' function expects the argument of 'i' to be the length of the buffer (in bytes) to be generated, not the actual value of the nonce length as per your code.
The 'crypto_secretbox_NONCEBYTES' constant is equal to 24, which is the required length for the nonce when using the 'crypto_secretbox_easy' function as per teh documentation -
Authenticated encryption[
^]
As per the documentation, your code should be -
var noncebytes = sodium.crypto_secretbox_NONCEBYTES;
var a = sodium.crypto_kx_keypair(), b = sodium.crypto_kx_keypair();
var p = sodium.crypto_kx_client_session_keys(a.publicKey, a.privateKey, b.publicKey);
var nonce = sodium.randombytes_buf(noncebytes);
var e = sodium.crypto_secretbox_easy('my message', p.sharedRx, nonce);