question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error thrown on NextJS

See original GitHub issue

Hello, I was trying useDapp with NextJS earlier today and as soon as I pasted all the basic example code I got this error:

Screen Shot 2021-04-04 at 12 55 08 AM
Server Error
ReferenceError: window is not defined

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Call Stack
getItem
file:///Users/fede/Documents/learning/usedapp+nextjs/usedapp-test-web/node_modules/@usedapp/core/dist/src/hooks/useLocalStorage.js (6:16)
<unknown>
file:///Users/fede/Documents/learning/usedapp+nextjs/usedapp-test-web/node_modules/@usedapp/core/dist/src/hooks/useLocalStorage.js (29:52)
useReducer
file:///Users/fede/Documents/learning/usedapp+nextjs/usedapp-test-web/node_modules/react-dom/cjs/react-dom-server.node.development.js (1537:57)

This article talks about this issue with NextJS https://medium.com/frontend-digest/why-is-window-not-defined-in-nextjs-44daf7b4604e , but there are many more you can google.

Is there a way to get a fix for this so useDapp becomes NextJS compatible or it does not make sense at all for you guys? Can I help?

Thanks for your time! Have a great day!

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mrcm2000commented, Jun 30, 2021

Seems to be happening to me on the upgrade to 0.4.0 and works again if I downgrade to 0.3.24. (My first day using the project, but seems like it might be related to new version)

2reactions
bitfedecommented, Apr 5, 2021

@marekkirejczyk YES!!! It is!!! Amazing!! You guys are awesome! I had a little heart attack thought I hit a dead end, but this fix finally unblocked me. Thank you so much guys!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Advanced Features: Error Handling - Next.js
Handle errors in your Next.js app. ... Render a fallback UI after an error is thrown; Provide a way to reset the Application's...
Read more >
reactjs - throw an error with a statusCode inside NextJs to test ...
I have been trying to create a page named errortest and inside that page, I want to throw an error with a given...
Read more >
Testing and error handling patterns in Next.js - LogRocket Blog
This error is not visible in production, and it is only thrown when the development server is running. The error overlay often gives...
Read more >
Handling API errors in Next.js - By Giancarlo Buomprisco
Learn how to write a Next.js middleware pipe to automatically and elegantly handle exceptions in your API functions.
Read more >
Next.js API - Global Error Handler Example & Tutorial
This is an example Next.js API route handler that accepts HTTP GET requests and shows how to throw different exceptions that will be...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found