react-native: New LogBox won't disable warnings with 'console.disableYellowBox'
Description
After enabling the experimental/unstable new logbox with
require('react-native').unstable_enableLogBox();
the warnings won’t be disabled when setting
console.disableYellowBox = true;
The reason for this is that there many warnings generated even by RN itself and I’d like to ave them hidden
React Native version:
$ react-native info info Fetching system and libraries information… System: OS: macOS Mojave 10.14.6 CPU: (8) x64 Intel® Core™ i7-4980HQ CPU @ 2.80GHz Memory: 715.46 MB / 16.00 GB Shell: 3.2.57 - /bin/bash Binaries: Node: 11.12.0 - /usr/local/bin/node Yarn: 1.7.0 - ~/.npm-packages/bin/yarn npm: 6.13.6 - ~/.npm-packages/bin/npm Watchman: 4.7.0 - /usr/local/bin/watchman Managers: CocoaPods: 1.8.4 - /usr/local/bin/pod SDKs: iOS SDK: Platforms: iOS 13.2, DriverKit 19.0, macOS 10.15, tvOS 13.2, watchOS 6.1 Android SDK: API Levels: 28, 29 Build Tools: 28.0.2, 28.0.3, 29.0.3 Android NDK: 20.1.5948944 IDEs: Android Studio: Not Found Xcode: 11.2.1/11B500 - /usr/bin/xcodebuild Languages: Python: 2.7.16 - /usr/bin/python npmPackages: @react-native-community/cli: Not Found react: 16.11.0 => 16.11.0 react-native: 0.62.0 => 0.62.0 npmGlobalPackages: react-native: Not Found
Steps To Reproduce
- Enable the unstable api:
require('react-native').unstable_enableLogBox();
- Try to disable the warnings:
console.disableYellowBox = true;
Expected Results
The Yellow box (small toast in the new version) should not be there
Snack, code example, screenshot, or link to a repository:
n/a
Thank you 😻
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 8
- Comments: 36 (4 by maintainers)
@hramos I tried doing the same, but apparently,
LogBox
isn’t exported yet, if I try to import itimport { LogBox } from 'react-native'
it comes back undefined. Or should I create a separate issue for that?Temporary solution.
ignoreWarnings.js
App.js
But LogBox.ignoreLogs([“pattern to ignore”]) doesn’t work. @rickhanlonii
x2
You even not reviewed this thread. Just closed it. 😱
LogBox.ignoreLogs
is not workingBut
LogBox.ignoreLogs(["pattern to ignore"])
doesn’t work. @rickhanloniiHere is a temporary workaround in case someone needs:
That disables all warnings that start with an empty string, in other words, all warnings. This works even if
unstable_enableLogBox
is set.Sad that the actual LogBox doesn’t work correctly and we have to hack it through!
This error is shown in console, even with ignoreLogs specific, global, etc. even with ignoreAllLogs(true)
VirtualizedLists should never be nested inside plain ScrollViews
Does not work for me on 0.63.2 The import does not work.
Recommended Solution
LogBox added two new methods for controlling logs:
LogBox.ignoreLogs(["pattern to ignore"])
: Use this when you want to ignore a specific list of warnings (such as when a library is causing a warning that you cannot fix). It is not recommended to use this for warnings that you do have control of fixing.LogBox.ignoreAllLogs()
: Replacesconsole.disableYellowBox
. Use this to temporarily disable all warnings in development. It is not recommended to check this in as it will disable warnings for your entire app.Also, many of the the warnings in the above Temporary Solution from @SohelIslamImran should not be ignored. These warnings include deprecation warnings which should be fixed so that your code is ready to upgrade to a future versions that removes the deprecations. Ignoring these warnings will result in your code throwing later.
This worked for me, you’re a legend for this
Here is an example of how to ignore warning “Non-serializable values were found in the navigation state”:
Can confirm that this works on 0.63^
@nicoburns ~Yh currently using 0.63.1 and trying to ignore/disable some warnings but can’t seem to import them~ Oops my bad, had the wrong version of the type definition installed 🤦
This issue needs to be reopened, but as of now, this is seems to be the valid solution.
Calling
LogBox.ignoreAllLogs()
,LogBox.ignoreAllLogs(true)
, andLogBox.ignoreLogs('')
doesn’t seem to work in react-native 0.64.3. I tried making the calls globally at the entry of my app code.I’ll go back to replacing
console.warn
for now.I suspect it’s not working, since hermes doesn’t allow to monkey-patch console. This temporary didn’t work for me neither.
Guys, be careful where the error occurs, more precisely in which screen because the warning may appear after you have ignored it.
I don’t understand why it’s not global, but for me that was the problem.
ReactNative.LogBox.ignoreAllLogs(true);
In React-Native 0.63, this will prevent annoying yellow warning box in screen. You can add above line in root app function.This is working for me. Well done
Thank you very much for this suggestion. Worked right way.
IgnoreLogs is still not working in my cljs react native app with react native version
0.71.2
LogBox.ignoreLogs is not working
@kingdomstrategies I’m using ClojureScript but you can probably understand what I did even if you aren’t familiar with ClojureScript.
Basically, create a new variable and assign
console.warn
to it to store the original function, then redefineconsole.warn
to a new function that only delegates toconsole.warn
if the message isn’t one you want to filter out.Let me know if you need more help with a pure JS/TS solution.
@bpringe How did you replace console.warn? I have tons of useless warnings being logged to my console regarding packages I have no control over and it’s making it impossible to debug usefully using the console.
For some reason
YellowBox.ignoreWarnings(['']);
completely turns off my error box, when I raise an exception I see a white screen, if I uncomment this line, the error is shown with the new log box as expected.