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

TypeError: Read error for undefined : buffer[bufferReader] is not a function #124

Closed
Plagiatus opened this issue Feb 5, 2025 · 4 comments

Comments

@Plagiatus
Copy link

I'm getting the above issue when trying to include prismarine-nbt in a svelte / vite frontend web project.

Image

My relevant code snippet:

import * as nbt from "prismarine-nbt";

export async function readNBTFile(file: File) {
    const buffer = await file.arrayBuffer();
    console.log(buffer);
    const { parsed, type } = await nbt.parse(buffer); // <- error happens here
    console.log({ parsed, type });
}

using the same code (but with callbacks instead of async/await) it works fine with nbt.js, however it's a no longer maintained project so I'd very much prefer to use this one instead.

@extremeheat
Copy link
Member

You need to pass a Node.js Buffer, not an ArrayBuffer

@Plagiatus
Copy link
Author

I was afraid something like that would be the case. This unfortunately makes using it purely on the frontend very inconvenient.

Thanks anyways.

@extremeheat
Copy link
Member

If you want to use prismarine-nbt (a nodejs library) on the web you will need to transpile to something browser compatible as with any other Node.js library.

Tool like browserify or webpack can do this. Those will implement the Node.js Buffer object that you can then instantiate to pass into prismarine-nbt. We also have a section on this in the readme https://github.com/PrismarineJS/prismarine-nbt?tab=readme-ov-file#browser-usage

@extremeheat
Copy link
Member

Since this has been brung up a few times (eg #56), we could do some sanity check before and maybe some conversion inside parse (Blob/ArrayBuffer => Node.js Buffer) to handle some of the handleable user mistakes

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

No branches or pull requests

2 participants