Skip to content
New issue

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

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

Already on GitHub? # to your account

relaxed-json require results to an empty object in Electron #9

Closed
sboudouk opened this issue Mar 29, 2016 · 7 comments · Fixed by #15
Closed

relaxed-json require results to an empty object in Electron #9

sboudouk opened this issue Mar 29, 2016 · 7 comments · Fixed by #15

Comments

@sboudouk
Copy link

Hi.

I'm trying to use your relaxed-json in my Electron app. Here is a simple code, GetDeviceList() is triggered on a button-push action:

const driver = require('meteor_driver').MeteorConnection.MeteorConnection;
const relaxed = require('relaxed-json');

const connection = new driver();

function GetDeviceList() {

    console.log(connection.port);
    console.log("Launching");
    console.log(relaxed);
    relaxed.transform('[{id:0,},{id:1,},{id:2,},]');
}

The console.log show me an empty object. And I got an error message Uncaught TypeError: relaxed.transform is not a function.

Otherwise, the package works properly when it's not used with electron.

Note that I don't encounter any require-related issue, so the modules must be valid isn't ?

@dustinkesner
Copy link

I noticed the same issue with node-webkit. Were you able to find a resolution to the issue? If so, can you share your findings?

@dominictarr
Copy link

I've just also had this problem.
the problem is that it checks whether window is defined first, and creates a global. in electron (or browserify) window is defined, but so is module.

it's only a two line change, just swap the order of this if-else https://github.com/phadej/relaxed-json/blob/master/relaxed-json.js#L577-L581
I would make a pull request, but it appears that this module is no longer maintained.

solution is to use hjson https://www.npmjs.com/package/hjson instead

@0o-de-lally
Copy link

+1 seems like on the client side in Meteorjs the require('relaxed-json') is resulting in an empty object. @phadej can you accept the pull request?

@0o-de-lally
Copy link

@phadej @dominictarr for Meteorjs, what works is removing the 'else' statement, like this:

  /* global window, module */
  if (typeof window !== "undefined") {
    window.RJSON = RJSON;
  }
  if (typeof module !== "undefined") {
    module.exports = RJSON;
  }

@0o-de-lally
Copy link

@phadej can we include this patch?

@phadej
Copy link
Owner

phadej commented Jan 18, 2017

The #14?

@0o-de-lally
Copy link

Yes that's correct. I have tested on meteor, not electron.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants