【发布时间】:2021-08-20 08:59:28
【问题描述】:
我尝试使用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 run 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)
【问题讨论】:
-
你可以尝试使用 yarn 来安装而不是 npm 吗?
yarn add html5-qrcode然后yarn install
标签: symfony webpack qr-code webpack-encore