question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't use this package with vite 3

See original GitHub issue

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.

Uncaught Error: Module "events" has been externalized for browser compatibility. Cannot access "events.EventEmitter" in client code.
    at Object.get (browser-external:events:9:13)
    at node_modules/readable-web-to-node-stream/node_modules/readable-stream/lib/_stream_readable.js (_stream_readable.js:32:10)
    at __require (music-metadata-browser.js?v=8f4e2ce6:3:50)
    at node_modules/readable-web-to-node-stream/node_modules/readable-stream/readable-browser.js (readable-browser.js:1:28)
    at __require (music-metadata-browser.js?v=8f4e2ce6:3:50)
    at node_modules/readable-web-to-node-stream/lib/index.js (index.js:4:27)
    at __require (music-metadata-browser.js?v=8f4e2ce6:3:50)
    at node_modules/music-metadata-browser/lib/index.js (index.js:6:39)
    at __require (music-metadata-browser.js?v=8f4e2ce6:3:50)
    at dep:music-metadata-browser:1:16

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 that npm 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.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
lennyanderscommented, Sep 5, 2022

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.

1reaction
Borewitcommented, Sep 5, 2022

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Troubleshooting - Vite
Error: Cannot find module 'C:\foo\bar&baz\vite\bin\vite.js' # · Switch to another package manager (e.g. pnpm , yarn ) · Remove & from the path...
Read more >
Cannot use some npm packages with vite · Issue #450 - GitHub
[vite] Dep optimization failed with error: Dependency "@azure/storage-blob" is attempting to import Node built-in module "fs". This will not ...
Read more >
Yarn 3.1, Vite 2.9, cannot find package vite - Stack Overflow
Yarn 3.1, Vite 2.9, cannot find package vite ... Show 3 more comments ... I had to stop using Yarn PnP and go...
Read more >
Troubleshooting | Vite Ruby
Verify that both vite and vite-plugin-ruby are in devDependencies in your package.json and have been installed by running bin/vite info . If you...
Read more >
Work with Vite and NX - Medium
I recommend using @nxext/vite. I checked several generators and this package was the better one (I can't say “best”, but better).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found