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.

[Bug] Lerna + react hooks

See original GitHub issue

Bug

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

  1. lerna init
  2. configure lerna for yarn workspaces
  3. copy template to /packages & provide package version
  4. run lerna bootstrap
  5. run yarn build

Expected Behavior

The build should succeed

Reproducible Demo

https://github.com/meesvandongen/bug-lerna-reactstatic

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
tannerlinsleycommented, Feb 15, 2019

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.

1reaction
tannerlinsleycommented, Feb 27, 2019

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).

Read more comments on GitHub >

github_iconTop 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 >

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