debug-js / debug

A tiny JavaScript debugging utility modelled after Node.js core's debugging technique. Works in Node.js and web browsers
MIT License
11.12k stars 929 forks source link

Does debug support React Native remote debugging. #685

Open ArvoGuo opened 5 years ago

ArvoGuo commented 5 years ago

Should I set other extra parameters, I didn't see any output

import {AppRegistry, Platform} from 'react-native';
import debug from 'debug';
const logger = debug('Test');
logger('test')
maxkomarychev commented 5 years ago

@ArvoGuo try adding debug.enable("*") before logger('test')

Qix- commented 5 years ago

I want to leave this open for the 5.x release because I get a lot of React Native questions and haven't used it myself. I want to investigate having some better support.

jacquesdev commented 5 years ago

@maxkomarychev - can you confirm why that works (I did not see it in the readme, although I guess this is being improved for v5). Using debug 4.10.0

The reason I'm asking is that in react-native 0.58.6 (using react 16.6.3) it was working ok without it, but when upgrading to react-native 0.59.8 (using react 16.8.3) it started working only when adding debug.enable("*").

xyz-tw commented 4 years ago

1 year late, but updating for anyone who references this.

This is the intended behaviour of metro creating an isolated environment. Refer to packages such as dotenv for how to pass environment variables to react native.

Also note that debug.enable(DEBUG) only needs to be set once, ideally in App.tsx

chmac commented 3 years ago

@Qix- React Native has AsyncStorage instead of localStorage. As the name suggests, it's async, promise based. From scanning the code it seems like debug expects storage.getItem() to return synchronously. If you're interested in adding support for React Native in future versions, adding support for AsyncStorage.getItem() as a fallback to localStorage.getItem() would be one way to go. If you need any support with this approach, feel free to ping me and I'll try to help out if I can.

ghoshabhi commented 2 years ago

Workaround was posted here: https://github.com/debug-js/debug/issues/640#issuecomment-441263230