Importing QRCodeStyling into NextJS immediately fails
See original GitHub issueUsing version 1.3.4
Simply adding
import QRCodeStyling from "qr-code-styling";
causes the package to immediately fail with server error: ReferenceError: self is not defined
The library does not check to verify it’s running client side.
Workaround for now is to replace the import statement with
if (typeof window !== "undefined") { console.log("i am client"); const QRCodeStyling = require("qr-code-styling"); }
Issue Analytics
- State:
- Created 3 years ago
- Comments:7
Top Results From Across the Web
self is not defined nextjs | The AI Search Engine You Control
Primarily, the issue came up when I started to run an import QRCodeStyling from "qr-code-styling"; in my NextJS setup. "next": "latest",; "qr-code-styling": "^ ......
Read more >Can't solve this error in next.js Deploying on Netlify. Imported ...
Next.js provides "public" folder for Static File Serving. You can find the details here. Put your image in public folder and change index.js ......
Read more >How to Generate QR Code Using Node.js - Section.io
This tutorial will provide the readers a detailed guide on how to generate QR code from URL and Text using Node JS.
Read more >easyqrcodejs - npm Package Health Analysis - Snyk
js 9.1)/ public ( >= Next.js 9.1) in the root directory. Script import Layout from '../components/Layout' ...
Read more >How to solve "window is not defined" errors in React and Next.js
Which only runs at the rendering phase, so it won't run on the server. Let's update our scroll.js component: // components/Scroll.js import ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I got it working like this. I’m not sure why I used qrCode update - you might be able to use your data directly in the options.
then
I created a react hook to use QRCodeStyling in NextJS. The following code should help it also uses typescript.