vue-qrcode-reader icon indicating copy to clipboard operation
vue-qrcode-reader copied to clipboard

Fix Import to work with SSR

Open JemiloII opened this issue 2 years ago • 1 comments

Describe the bug Every time I load this module on an ssr page with nuxt. My application throws an error as it is looking for browser globals. Please check for these globals so that it doesn't crash with an SSR load!

To Reproduce Create a nuxt with SSR enable and load the qrcode-stream element.

Screenshots Screenshot_1

Desktop (please complete the following information): ALL

Smartphone (please complete the following information): ALL

JemiloII avatar Aug 14 '21 19:08 JemiloII

It's difficult to eliminate these SSR errors. The library relies heavily on Web APIs. A workaround might be something like:

<template>
  <client-only>
    <qrcode-stream />
  </client-only>
</template>

<script>
export default {

  components: {
    'qrcode-stream': async () => {
      const { QrcodeStream } = await import("vue-qrcode-reader")
      return QrcodeStream
    }
  }

}
</script>

gruhn avatar Aug 15 '21 21:08 gruhn

This issue has been marked as stale. If there is no further activity it will be closed.

github-actions[bot] avatar Jul 22 '23 00:07 github-actions[bot]