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

Error: Invalid hook call #14

Open
GonzaloHuerta opened this issue Oct 28, 2020 · 6 comments
Open

Error: Invalid hook call #14

GonzaloHuerta opened this issue Oct 28, 2020 · 6 comments

Comments

@GonzaloHuerta
Copy link

I implemented add-to-home-screen-react in a project with react version 16.13.1 and it works perfect but in another project with version 17.0.1 it throws: Error: Invalid hook call. Any idea why? Thank you!

@stuf
Copy link

stuf commented Nov 9, 2020

The Invalid hook call error arises a lot of the time from React being bundled multiple times in the project — in this case you might have two different React versions installed; this library depends on React v16.13.1 (exact version16.13.1), while your project is running on v17.

Even if the version in dependencies were ^16.13.1 (from version 16.13.1 upwards until but not including 17.0.0) I'd guess it would still cause issues.

Edit: Been wrestling with the exact same error in another project (not through this library however, but found this from a discussion at work), where the problem was that there were multiple versions installed.

@stuf
Copy link

stuf commented Nov 9, 2020

@GonzaloHuerta However! If this is still a problem, or if it happens in the future, you might find success with specifying a resolver in your package.json file:

  "scripts": { ... },
  "dependencies": { ... },
  "resolutions": {
    "**/react": "^17.0.1",
    "**/react-dom": "^17.0.1"
  },
  ...

@AbuSM
Copy link

AbuSM commented Nov 15, 2020

Any news on this issue?

@AbuSM
Copy link

AbuSM commented Nov 16, 2020

IDK why, but I fixed this by removing node_modules from @ideasio/add-to-homescreen-react which is located in node_modules of application

@JuhQ
Copy link

JuhQ commented Jan 19, 2021

I had the same issue.

I think it's caused by this projects package.json declaring react as dependency, not as dev or peer dependency.

https://stackoverflow.com/questions/30451556/what-is-the-correct-way-of-adding-a-dependency-to-react-in-your-package-json-for

@tolmekian1453
Copy link
Contributor

tolmekian1453 commented Feb 12, 2021

Yeah, a common issue with React libs. I tried copying it into my src instead of including it in my package.json, but it won't build that way cause it uses some language extensions or something. So I forked it and removed the react deps altogether because I'm not sure what the peer dependencies should be set to.

This really should be fixed. In the meantime, for anyone who wants to use my fork, I warn you that I'm no expert, but here:
npm install git+https://github.com/tolmekian1453/add-to-homescreen-react
import AddToHomeScreen from '@ideasio/add-to-homescreen-react';

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

5 participants