Comments (9)
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:
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@esbuild-plugins/node-modules-polyfill": "^0.2.2",
"music-metadata-browser": "^2.5.9",
"rollup-plugin-polyfill-node": "^0.12.0",
"vite": "^4.1.4",
"vue": "^3.2.45",
from music-metadata-browser.
I also struggled a little bit to use this package with vite, react & typescript, but here is how i managed to make it run:
npm install buffer @esbuild-plugins/node-globals-polyfill @esbuild-plugins/node-modules-polyfill
then in vite.config.js
:
export default defineConfig({
// your other settings...
optimizeDeps: {
esbuildOptions: {
define: {
global: 'globalThis',
},
plugins: [
NodeGlobalsPolyfillPlugin({
buffer: true,
}),
],
},
},
});
Then it works flawless.
My packages versions:
"vite": "^3.2.3",
"music-metadata-browser": "^2.5.9",
"react": "^18.2.0",
"react-dom": "^18.2.0",
from music-metadata-browser.
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.
from music-metadata-browser.
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.
from music-metadata-browser.
I bumped into the same issue, also getting ReferenceError: global is not defined
and ReferenceError: process is not defined
(both which can be overrided in vite config define
).
from music-metadata-browser.
One of the things you may run into using the ESM is the way Node.js modules are imported. They use the node:
URL prefix. I am not sure if that helps, or makes it very difficult to polyfill Node.js modules.
from music-metadata-browser.
I already handled that with an alias in vite, from node:buffer to buffer.
https://github.com/lennyanders/music-metadata-browser-8-with-vite-3/blob/28bc592464a50e6c0be8672a9169c393393fecc0/vite.config.js#L10
from music-metadata-browser.
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 parseBlob
which music-metadata-browser adds. I want to move those into music-metadata.
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?
from music-metadata-browser.
Thanks for sharing your solution @subframe7536
from music-metadata-browser.
Related Issues (20)
- Get rid of assert dependency
- Bug with in-browser implementation HOT 6
- Uncaught ReferenceError: exports is not defined HOT 2
- 2.5.0 Version updates Break Some Features on Safari HOT 5
- 'TypeError: this.parseReadableStream is not a function' on latest version 2.5.1 HOT 2
- Broken data in metadata result HOT 3
- Incompatibility with Webpack 5 HOT 3
- TypeError: can't access property "call", Stream is undefined HOT 9
- No title or artist metadata from URL streams HOT 4
- Add MusicSource to online demos HOT 1
- fetchFromUrl doesn't include credentials HOT 1
- Source map warnings.
- Using music-metadata 7.x instead on 8.x HOT 2
- use Range header to fetch metadata instead of whole file? HOT 1
- Nuxt 3 compatibility HOT 2
- Multiple blobs at once not parsing in WebWorker in Firefox HOT 5
- Wrong "Sample-rate" in "Audio Tag Analyzer" demo
- Option to avoid parsing entire file? HOT 1
- Polyfill required with Vite 4 - Buffer is not defined
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from music-metadata-browser.