Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Requires hack to work with React Native remote debugging #286

Closed
felixmc opened this issue Jun 4, 2016 · 6 comments
Closed

Requires hack to work with React Native remote debugging #286

felixmc opened this issue Jun 4, 2016 · 6 comments

Comments

@felixmc
Copy link

felixmc commented Jun 4, 2016

Because the document global is not defined in react native, the following line of code throws an error when using the module:
https://github.com/visionmedia/debug/blob/master/dist/debug.js#L369

The error looks like this in react native:
https://www.dropbox.com/s/kt12zlnpvtdn3pz/Screenshot%202016-06-03%2022.06.20.png?dl=0

My current workaround includes defining the following line before initializing debug:

global.document = { documentElement: { style: { WebkitAppearance: true } } }

Setting the value to true allows it to use colorful output when using Chrome for remote debugging.

Maybe there's a way to detect react native environment to avoid the hack above?

@inetfuture
Copy link

How do you set the filter since there is no LocalStorage?

@tianjianchn
Copy link

@inetfuture manually set it, like:

if(!window.localStorage) window.localStorage = {};
window.localStorage.debug = '*';

@thebigredgeek
Copy link
Contributor

This should be fixed. Closing

@jhilden
Copy link

jhilden commented Oct 30, 2018

Unfortunately I was not able to get debug working with react-native. I imported debug, I added the snippet posted by @tianjianchn, but I'm not seeing any log output in the remote chrome debugger console. Anybody have any suggestions?

@ArvoGuo
Copy link

ArvoGuo commented Feb 18, 2019

Unfortunately I was not able to get debug working with react-native. I imported debug, I added the snippet posted by @tianjianchn, but I'm not seeing any log output in the remote chrome debugger console. Anybody have any suggestions?

+1

@jhilden
Copy link

jhilden commented Feb 22, 2019

It looks like the issue for me was that namespaces were not enabled properly.

Ended up wrapping debug in this way and importing this module instead of the orginal package.

import Config from 'react-native-config'
import createDebug from 'debug'

if (Config.DEBUG_NAMESPACES) {
  createDebug.enable(Config.DEBUG_NAMESPACES)
}

export default createDebug

Probably not ideal yet, but it works for us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants