score:18

Accepted answer

if this issue happens while you're linking the local version of your library in your main project to speed up the development. it might be related to "duplicate version of react".

https://reactjs.org/warnings/invalid-hook-call-warning.html

this problem can also come up when you use npm link or an equivalent. in that case, your bundler might “see” two reacts — one in application folder and one in your library folder. assuming myapp and mylib are sibling folders, one possible fix is to run npm link ../myapp/node_modules/react from mylib. this should make the library use the application’s react copy.

in short:

  • run npm link in /your-app/node_modules/react. this should make the react's global link.
  • run npm link react in /your-ui-library. this should make the library use the application’s react copy.

score:1

i have the same issue, working with a rush monorepo, configuring ui-package and building the apps using nextjs.

the solutions was add the follow code on package.json

"resolutions": {
  "react": "17.0.1", // verificate your react version
  "react-dom": "17.0.1"
}

see more here: https://github.com/vercel/next.js/issues/9022#issuecomment-728688452


Related Query

More Query from same tag