html5-二维码webpack encore

html5-qrcode webpack encore

我尝试使用 https://github.com/mebjas/html5-qrcode 使用 webpack

 npm i html5-qrcode --save


+ html5-qrcode@2.0.11
added 2 packages from 2 contributors in 8.99s
root@21ce69a5652

/application# yarn 运行 encore dev --watch

在js文件中

import("html5-qrcode");

编译成功但控制台报错

ncaught (in promise) TypeError: Cannot read property 'Html5Qrcode' of undefined
    at Object.<anonymous> (html5-qrcode.min.js:6)
    at Object../node_modules/html5-qrcode/dist/html5-qrcode.min.js (html5-qrcode.min.js:8)
    at __webpack_require__ (bootstrap:84)
    at __webpack_require__.t (bootstrap:182)


require('html5-qrcode');

喜欢导入但错误是

Uncaught TypeError: Cannot read property 'Html5Qrcode' of undefined
    at Object.<anonymous> (html5-qrcode.min.js:6)
    at Object../node_modules/html5-qrcode/dist/html5-qrcode.min.js (html5-qrcode.min.js:8)
    at __webpack_require__ (bootstrap:79)
    at Module../assets/components/ScannerQrCode.js (ScannerQrCode.js:6)
    at __webpack_require__ (bootstrap:79)
    at Module../assets/components/Games.js (app.js:374)
    at __webpack_require__ (bootstrap:79)
    at Module../assets/components/Home.js (app.js:748)
    at __webpack_require__ (bootstrap:79)
    at Module../assets/app.js (app.js:1)

(作者在此)这已在最新版本中得到修复 2.1.0

如果这解决了问题,请告诉我,否则请告诉我或直接在 GitHub 项目上提交问题 - mebjas/html5-qrcode