[Bug] Lerna + react hooks
See original GitHub issueBug
When running using lerna & react hooks, react-static is not able to export.
Instead, this error is shown:
Invariant Violation: Failed exporting HTML for URL / (src\pages\index.tsx): Minified React error #307; visit https://reactjs.org/docs/error-decoder.html?invariant=307
According to that page, this is the error: Hooks can only be called inside the body of a function component
If I manually place the global node_modules
in the local project folder, the build succeeds.
Environment
System:
OS: Windows 10
CPU: (8) x64 Intel(R) Core(TM) i7-2700K CPU @ 3.50GHz
Memory: 6.84 GB / 15.95 GB
Binaries:
Node: 11.9.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.13.0 - ~\AppData\Roaming\npm\yarn.CMD
npm: 6.5.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Edge: 44.17763.1.0
Internet Explorer: 11.0.17763.1
Dependencies:
react: 16.8.1
react-dom: 16.8.1
react-static: 6.0.18
Steps to Reproduce the problem
lerna init
- configure lerna for yarn workspaces
- copy template to
/packages
& provide package version - run
lerna bootstrap
- run
yarn build
Expected Behavior
The build should succeed
Reproducible Demo
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
[lerna] Invariant Violation: Hooks can only be called inside the ...
Hello,. I have an error regarding hooks in a lerna architecture project where we import a ux lib made of style component inside...
Read more >React: Lerna React hooks error on monorepo - Stack Overflow
When I use material ui components instead of DIV's i get error that says: Invalid hook call. Hooks can only be called inside...
Read more >[Solved]-React: Lerna React hooks error on monorepo-Reactjs
Coding example for the question React: Lerna React hooks error on monorepo-Reactjs.
Read more >Invalid hook call issue solved when configuring with Lerna ...
0 . The actual react error states: Invalid hook call. Hooks can only be called inside of the body of a function component....
Read more >Fix React Issues in Lerna using Yarn Workspaces
When I run this app, React throws an error called "Error: Invalid hook call" as shown below. Error thrown when using Lerna to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This is a bug with react in general when using lerna or linked dependencies. We’re working on a workaround that will hopefully fix this.
Another scenario that causes this bug is when there are 2 versions of React being loaded in the same application. Using Hooks will amplify this issue sooner, so you need to make sure you are only relying on a single version of react for your whole app. Try running
yarn why react
to see which/how many versions you have installed.We released a fix that should force resolve any react imports to the same version (the one resolved from your project root).