-
-
Notifications
You must be signed in to change notification settings - Fork 21
Can't use this package with vite 3 #836
Comments
I bumped into the same issue, also getting |
I think you need to polyfill: music-metadata-browser is CommonJS module. Eventually I would like to provide an ES-Module music-metadata also works in client side environment. Closes effort that can be found in the es-module-with-browser-support branch. I welcome help with that. |
I got it working using a buffer, events and utils polyfill and a bit of vite config trickery. Here is the branch with the working code: https://github.com/lennyanders/music-metadata-browser-8-with-vite-3/tree/music-metadata-with-polyfills I might look into you'r branch though (and maybe music-metadata itself), since I'm not so happy using it like this. |
One of the things you may run into using the ESM is the way Node.js modules are imported. They use the |
I already handled that with an alias in vite, from node:buffer to buffer. |
Hi @lennyanders, I had a look to your music-metadata-with-polyfills. So that is the ESM way music-metadata. That's great, first time I think I actually see it working in the browser! What you do not have in music-metadata version 8.0.1 are the specialized browser functions, like The idea es-module-with-browser-support branch was to add that part. Are you willing to further develop the browser compatibility of the music-metadata ESM version? |
I also struggled a little bit to use this package with vite, react & typescript, but here is how i managed to make it run:
then in
Then it works flawless.
|
update: just one plugin: https://github.com/grikomsn/vite-plugin-ngmi-polyfill I solved it with vite4 and vue3. Here is my config export default defineConfig({
...sharedConfig,
build: {
rollupOptions: {
// for production
plugins: [rollupNodePolyfillsPlugin()],
},
},
resolve: {
alias: {
// by node-globals-polyfill
events: 'rollup-plugin-node-polyfills/polyfills/events',
},
},
optimizeDeps: {
esbuildOptions: {
plugins: [
NodeGlobalsPolyfillPlugin({ buffer: true, process: true }),
NodeModulesPolyfillPlugin(),
],
},
},
}) My packages versions:
|
Thanks for sharing your solution @subframe7536 |
This now implemented: you may try music-metadata ≥ 9 , which is guaranteed Buffer free. |
Hey, I currently use music-metadata with a buffer polyfill and vite 2 in my project. I would like to switch to this package (which is intended for the use in the browser) and vite 3. Sadly, it does not work, and I get the following error. I tried to polyfill the events module, but that led to more similar errors and I got into polyfilling hell.
I created a minimal reproduction of the issue here: https://github.com/lennyanders/music-metadata-browser-8-with-vite-3.
There you just need to execute
npm i
, after thatnpm start
and then you can see the error in the browser console.Thanks for looking into it and if I can be of any help, please let me know.
The text was updated successfully, but these errors were encountered: