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

Since 2.3.1/2.3.2 localStorage "debug" is removed every time (wrong Electron check) #330

Closed
ibc opened this issue Nov 12, 2016 · 5 comments

Comments

@ibc
Copy link
Contributor

ibc commented Nov 12, 2016

After upgrading my debug dependency from 2.3.0 to 2.3.2 nothing works again.

My index.html runs the following code before running any JS library:

<script>
   localStorage.setItem('debug', '*');
</script>

<!-- Load JS libs now -->

It has worked with any previous version of the debug library. Now it doesn't and nothing it logged.

In fact, once the the JS library (which includes the debug dependency) is loaded, localStorage.getItem('debug') returns false.

This is critical.

@ibc
Copy link
Contributor Author

ibc commented Nov 12, 2016

My JS app uses browserify. However I've checked that lib/browser.js is loaded (as it must be), so that's not the problem.

@ibc
Copy link
Contributor Author

ibc commented Nov 13, 2016

The issue is here, in lib/browser.js (I've added some console warns):

function load() {
  var r;
  try {
    r = exports.storage.debug;
    console.warn('1 - r:%o', r);
  } catch(e) {}

  // If debug isn't set in LS, and we're in Electron, try to load $DEBUG
  if ('env' in (typeof process === 'undefined' ? {} : process)) {
    r = process.env.DEBUG;
    console.warn('2 - r:%o', r);
  }

  return r;
}

And this is the output:

browser.js:152 1 - r:"* -engine* -socket* *ERROR* *WARN*"
browser.js:158 2 - r:undefined

This is, initially it reads the debug key from localStorage. And after that, it checks whether a process global (or local scope) variable does exist, and in that case it "assumes" that we are in Electron.

I'm using envify which INDEED declares process as a local variable in order to allow the JS app in the browser check process.env stuff. That does NOT mean that we are in Electron.

Please, fix that. If Electron checks are needed do it, but don't break other valid usages of process.

@ibc ibc changed the title Since 2.3.1 or 2.3.2 localStorage "debug" is removed every time Since 2.3.1/2.3.2 localStorage "debug" is removed every time (wrong Electron check) Nov 13, 2016
@jordalgo
Copy link

jordalgo commented Nov 15, 2016

Any word on getting this fix into a new version ?

@ibc
Copy link
Contributor Author

ibc commented Nov 19, 2016

Guys, this is a terrible issue for which there is already a fix in master. Please, publish a new NPM version of debug module.

@TooTallNate
Copy link
Contributor

2.3.3 published

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

3 participants