安装
pnpm
pnpm add react-barcode-scanneryarn
yarn add react-barcode-scannernpm
npm install react-barcode-scanner脚手架
Vite
建议使用最新版本的 Vite。如果 Vite 4 或更低版本无法预构建 ESM-only polyfill,可以将上游依赖排除在依赖优化之外:
export default defineConfig({
optimizeDeps: {
exclude: ['@preflower/barcode-detector-polyfill']
}
})🙏 感谢 @louispotok (opens in a new tab) 对本章节的帮助