create-react-library icon indicating copy to clipboard operation
create-react-library copied to clipboard

Error: Invalid hook call [styled-components]

Open vaibhav6233m opened this issue 4 years ago • 2 comments

I created a new app using create-react-app react-boilerplate template which uses styled-components.

Imported custom-ui-library in the project which is also internally using styled-components. "custom-ui-library": "file:../../custom-ui-library",

But getting the similar errors as discussed in #197 .

image

I tried peerDependencies fix provided by @beTTostd as well, but nothing seems to be working so far.

It works with the example project and plain create-react-app project when I add these dependancies in package.json

    "custom-ui-library": "file:../../custom-ui-library",
    "react": "file:../../custom-ui-library/node_modules/react",
    "react-dom": "file:../../custom-ui-library/node_modules/react-dom",
    "react-scripts": "file:../../custom-ui-library/node_modules/react-scripts"

Am I missing something? are there any other configurations needed in v3? Please suggest.

vaibhav6233m avatar Oct 16 '20 16:10 vaibhav6233m

maybe you've since figured this out, but in case anyone finds this issue in the future, the reason this happens is because of the file:// imports (this also happens with npm link). it's an issue with react and not with CRL.

https://github.com/facebook/react/issues/13991

rettgerst avatar Oct 25 '21 01:10 rettgerst

I faced similar issue before. I think you can solve it with using npm pack and install with the command npm i ../../custom-ui-library-x.y.z.tgz instead of npm i ../../custom-ui-library.

I wrote how to solve here

ysuzuki19 avatar Oct 25 '21 11:10 ysuzuki19