Install
pnpm
pnpm add react-barcode-scannerPolyfill
ZBar
ZBar is included as a dependency and requires no additional installation; its WASM is approximately 230 kB. It does not support aztec, data_matrix or pdf417; use ZXing if you need these formats.
import 'react-barcode-scanner/polyfill'⚠️
Choose either the ZBar or ZXing polyfill, not both. A polyfill does not replace an existing native BarcodeDetector.
Scaffold
Vite
We recommend using the latest Vite version. If a project on Vite 4 or earlier fails to pre-bundle the ESM-only polyfill, exclude the upstream package from dependency optimization:
export default defineConfig({
optimizeDeps: {
exclude: ['@preflower/barcode-detector-polyfill']
}
})🙏 Thank @louispotok for help to this chapter
Last updated on