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.

Invalid hook call on login page

See original GitHub issue

Describe the bug I’m getting the following error:

(node:18527) UnhandledPromiseRejectionWarning: Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
See https://fb.me/react-invalid-hook-call for tips about how to debug and fix this problem.
    at resolveDispatcher (/Users/david/workspace/dongwon-api/node_modules/react/cjs/react.development.js:1465:13)
    at Object.useState (/Users/david/workspace/dongwon-api/node_modules/react/cjs/react.development.js:1496:20)
    at ae (/Users/david/workspace/dongwon-api/node_modules/styled-components/dist/styled-components.cjs.js:1:13232)
    at processChild (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:3043:14)
    at resolve (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:2960:5)
    at ReactDOMServerRenderer.render (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:3435:22)
    at ReactDOMServerRenderer.read (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:3373:29)
    at renderToString (/Users/david/workspace/dongwon-api/node_modules/admin-bro/node_modules/react-dom/cjs/react-dom-server.node.development.js:3988:27)
    at html (/Users/david/workspace/dongwon-api/node_modules/admin-bro/lib/frontend/login-template.js:73:53)
    at processTicksAndRejections (internal/process/task_queues.js:94:5)
    at async /Users/david/workspace/dongwon-api/node_modules/@admin-bro/express/lib/authentication/login.handler.js:19:23

Installed libraries and their versions

To Reproduce Steps to reproduce the behavior:

  1. Use buildAuthenticatedRouter to create AdminBro router.
  2. Run the app & visit /admin

Additional context There’s a closed issue about this matter, but I was not able to resolve this problem after removing node_modules or by adding react & react-dom as dependencies.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:25 (3 by maintainers)

github_iconTop GitHub Comments

16reactions
yarikpwnzercommented, May 18, 2021

Fixed by using same react/react-dom versions as in admin-bro dependencies: “react”: “=16.13.1”, “react-dom”: “=16.13.1”

3reactions
mkayandercommented, Oct 2, 2021

Ok so i just wrote "styled-components": "=4.4.1" in my package.json and it started working 😂. From the third line of stacktrace at ae (C:\Users\maxim\WebstormProjects\portfolio\node_modules\styled-components\src\utils\isStaticRules.js:6:54) i saw that it also uses my newest styled-components package, then it goes to my latest React package. I use Yarn. I assume that it saw that my styled-components version and the one in adminjs are compatible (though not the same, i checked) so it linked it to share with adminjs. That somehow caused the usage of another React version i described above. Thats how i understand it, though it’s kinda a bit crazy. I would be glad if someone can clear this up more.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid Hook Call Warning
There are three common reasons you might be seeing it: You might have mismatching versions of React and React DOM. You might be...
Read more >
Invalid hook call. Hooks can only be called inside of the ...
I had this issue when I used npm link to install my local library, which I've built using cra . I found the...
Read more >
Invalid hook call on login page · Issue #810
Describe the bug I'm getting the following error: (node:18527) UnhandledPromiseRejectionWarning: Error: Invalid hook call.
Read more >
Form giving error : 'Error: Invalid hook call. Hook
Topic: Form giving error : 'Error: Invalid hook call. Hooks can only be called inside of the body of a function component. This...
Read more >
Login redirect but has Invalid Hook Call-Reactjs
Coding example for the question Reactjs - Login redirect but has Invalid Hook Call-Reactjs.
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