Closed olyop closed 4 months ago
I think you are missing buffer
dependency inclusion somewhere in your bundler.
Ok, I am using webpack so how do I make it include buffer
as a dependency?
Maybe this article can help you: How to Polyfill node core modules in webpack 5.
Thank you, I managed to find a solution. For anyone else looking, It's an issue with webpack 5.
For anyone using a modern bundler like vite
or snowpack
, you will have to add yarn add buffer
and create a polyfill file where you assign it the window object.
import { Buffer } from "buffer";
if (typeof window !== "undefined" && typeof Buffer === "undefined") {
window.Buffer = Buffer;
}
I was wondering whether this library could instead operate on Uint8Arrays instead of buffers?
I was wondering whether this library could instead operate on Uint8Arrays instead of buffers?
That's a good question, I have been been working on that behind the screens. One of the issues is that the TextEncoder is limited to utf-8 encoding and decoding in the Node.js implementation.
Related to:
For anyone using a modern bundler like
vite
orsnowpack
, you will have to addyarn add buffer
and create a polyfill file where you assign it the window object.import { Buffer } from "buffer"; if (typeof window !== "undefined" && typeof Buffer === "undefined") { window.Buffer = Buffer; }
I think you meant typeof window.Buffer === "undefined"
Also, if you are using rollup, I've found that you have to install events yourself. The plugins for rollup don't work right now, and they don't seem to be necessary.
Thanks for the great work! :)
Related: https://github.com/vitejs/vite/discussions/2785 (Using (Node’s) Buffer in your polymorphic Vite apps...)
Maybe we can get rid of Buffer Borewit/token-types#650, keeping this one open to represent the aim to get rid of Buffer. But it maybe that music-metadata replaces music-metadata-browser taking over as good enough browser compliant module.
music-metadata now offers Node.js free functionality for non Node.js engines.
Polyfilling Buffer or Node.js streams should belong to the past, and it also makes this package obsolete.
But... only available as ECMA Script Module (ESM), CommonJS is no longer supported.
Thank you for your work @Borewit
Just tested it out in a project and works great, no Buffer dependency needed
Thank you for your work @Borewit
Just tested it out in a project and works great, no Buffer dependency needed
I was a complex and a time consuming architectural change, so glad to hear it worked out for you, thanks for providing that feedback.
I am receiving this error:
I am importing the package like this:
import { parseBlob } from "music-metadata-browser"
I am calling the function like this:
const metadata = await parseBlob(audio)
I have already checked that I am passing a object of type
File
usinginstanceof
.I am using the latest version of music-metadata and Chrome.