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.

React Hook "useBabelRc" cannot be called at the top level

See original GitHub issue

Following “Minimize bundle size” guide with my CRA (option 2 with babel-plugin-import), I get a red warning in VSCode on override(useBabelRc())within the file config-overrides.js, but no compilation error.

“React Hook “useBabelRc” cannot be called at the top level. React Hooks must be called in a React function component or a custom React Hook function”.

However, I can access any of the components, the ThemeProvider to pass the dark mode works.

When building the code, I have a bundle size of 104kB. Not sure what it should be.

  • [ x] The issue is present in the latest release.
  • [x ] I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 😯

VSCode red warning and no compilation error.

Expected Behavior 🤔

No warning with VSCode.

Steps to Reproduce 🕹

  • yarn add -D babel-plugin-import
  • create & copy the file .babelrc.js from the doc in root folder
  • yarn add -D react-app-rewired customize-cra
  • create & copy config-overrides.js in root folder => red warning override(useBabelRC())
  • package.json: script.start: react-app–rewired start => no compilation error

My code & package.json https://github.com/ndrean/navbar where you can check the settings.

Steps:

Context 🔦

Drying code with import { Button, TextField } from '@material-ui/core';.

Your Environment 🌎

`npx @material-ui/envinfo`
  Don't forget to mention which browser you used.
  Output from `npx @material-ui/envinfo` goes here.

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
ndreancommented, Dec 15, 2020

Yes, as mentioned, with or without the flag “eslint-disable react-hooks”, it seems to works as I can use the one-liner multiple import argument. Most probably not related to MUI I believe.

1reaction
mnajdovacommented, Dec 15, 2020

I’d say you should just suppress that eslint error in the config-overrides-.js file. Based on the documentation this is the correct usage, to it should be safe.

https://codesandbox.io/s/material-ui-issue-forked-q5g1n?file=/config-overrides.js:0-48

Read more comments on GitHub >

github_iconTop Results From Across the Web

React Hook "useBabelRc" cannot be called at the top level
"React Hook "useBabelRc" cannot be called at the top level. React Hooks must be called in a React function component or a custom...
Read more >
Cannot read property 'use' of undefined, react-app-rewired
React Hook "useEslintRc" cannot be called at the top level. React Hooks must be called in a React function component or a custom...
Read more >
Customize Create React App without Ejecting - Code Daily
The one we will use is called useBabelRc . This will allow us to tell Create React App and have Babel also utilize...
Read more >
Introducing new plugins in Babel to create react app
useBabelRc () is for using .babelrc in your project. By default create react app does not allow you to use .babelrc so you...
Read more >
Minimizing bundle size - Material UI - MUI
UX: The Babel plugin enables top-level tree-shaking even if your bundler doesn't support it. DX: The Babel plugin makes startup time in dev...
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