What is happning
On vue2.6 + webpack, an application as follow is working well.
<template>
<v-app>
<QR/>
<v-main>
</v-main>
</v-app>
</template>
<script>
import QR from 'qrcode-of-this-site'
export default {
components: {QR},
}
</script>
Where qrcode-of-this-site imported at line#10 is my ES6 module and using another external CommonJS module qrcode.
However, on vue3.2 + vite, this application reports an error as follows:
Uncaught SyntaxError: The requested module '/node_modules/qrcode/lib/browser.js?v=0df8a00b' does not provide an export named 'default' (at QRcode.vue:11:8)
watching files
The file /node_modules/qrcode/lib/browser.js is as follows:
...
exports.create = QRCode.create
exports.toCanvas = renderCanvas.bind(null, CanvasRenderer.render)
exports.toDataURL = renderCanvas.bind(null, CanvasRenderer.renderToDataURL)
// only svg for now.
exports.toString = renderCanvas.bind(null, function (data, _, opts) {
return SvgRenderer.render(data, opts)
})
QRcode.vue is as follows:
<template>
<v-layout column align-center class="white--text">
<v-flex>
<canvas id="qr"></canvas>
</v-flex>
QR code for this App
</v-layout>
</template>
<script>
import QRCode from 'qrcode';
export default {
mounted: function(){
var currentUrl = window.location.origin;
console.log(currentUrl);
QRCode.toCanvas(document.getElementById('qr'),
currentUrl, { toSJISFunc: QRCode.toSJIS }, function (error) {
if (error) console.error(error)
console.log('success!')
})
}
}
</script>
Also, I've tried import {toCanvas} from 'qrcode';
at line #11 of QRcode.vue, and the error is reported as follows:
Uncaught SyntaxError: The requested module '/node_modules/qrcode/lib/browser.js?v=0df8a00b' does not provide an export named 'toCanvas' (at QRcode.vue:11:9)
even toCanvas is certainly exported by /node_modules/qrcode/lib/browser.js
My question
Can't the pair of vue3 and vite import the CommonJS module as a default? Are there any necessary settings to run this app?
Reproducing environment
The full environment for reproducing is available as follows:
- Vue2 env (working well) https://github.com/UedaTakeyuki/QRcodeVue2
- Vue3 env (import error) https://github.com/UedaTakeyuki/QRcodeVue3