preflower / react-barcode-scanner

A lightweight React scan library based on modern API
https://reactbarcodescanner.vercel.app/
MIT License
18 stars 4 forks source link

Document Vite workaround for import.meta.url #231

Closed louispotok closed 2 months ago

louispotok commented 2 months ago

Hi, I just tried to get this working with Vite. It didn't work out-of-the-box, which looks like it's caused by an issue with Vite, but there's a quick workaround. It might save other people some time if this was documented here?

I'm out of my depth on understanding the issue, but it looks like Vite has problems with import.meta.url -- causing errors in development mode and warnings in production mode. The polyfill library that this library relies on seems to trigger those issues. The workaround is to exclude the polyfill library from being optimized by vite in the vite config:

  optimizeDeps: {
    exclude: ['@preflower/barcode-detector-polyfill']
  },
preflower commented 2 months ago

I have rewritten the project document and added scaffold use guide; https://reactbarcodescanner.vercel.app/docs/install