Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Next.js #38

Open
wesbos opened this issue Jan 1, 2021 · 5 comments
Open

Issues with Next.js #38

wesbos opened this issue Jan 1, 2021 · 5 comments

Comments

@wesbos
Copy link

wesbos commented Jan 1, 2021

Hello - I think this fork does SSR, right?

When I import it like so:

import QrReader from 'react-qr-scanner';

I get this issue: SyntaxError: Cannot use import statement outside a module pointing to > 1 | module.exports = require("react-qr-scanner");

I looked through the source and can't seem to find why it would think it's cjs. Any ideas?

It does work if I use next.js dynamic import, but then that that annoy as it re-imports it when it re-renders.

const QrReader = dynamic(() => import('react-qr-scanner'));
@wesbos
Copy link
Author

wesbos commented Jan 6, 2021

I think this has to do with the Module not being shipped as CJS, or with a .MJS extension?

@csellis
Copy link

csellis commented Mar 19, 2021

Did you make any progress @wesbos ? I'm looking at this same use case

@wesbos
Copy link
Author

wesbos commented Mar 24, 2021

Yes, I used an alternative lazy import package for React.I forget the name, but it was the big one...

@theabdulmateen
Copy link

Yes, I used an alternative lazy import package for React.I forget the name, but it was the big one...

By this do you mean wait till the page is delivered from nextjs and then load the QrReader? In that case you would only need to something of this sort right?

useEffect(() => {
  setHasRendered(true)
}, [])
...
...

<div>
{hasRendered && (
    <QrReader
      ...
    />
  )}
</div>

@ninest
Copy link

ninest commented May 17, 2021

Apart from the above solution, this works for me

<div>
  {typeof window !== "undefined" && (
    <>
      <QRReader
        onScan={onScan}
        onError={onError}
      ></QRReader>
    </>
  )}
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants