phadej / relaxed-json

Relaxed JSON is strict superset JSON, relaxing strictness of vanilla JSON
http://oleg.fi/relaxed-json/
Other
80 stars 8 forks source link

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

Closed sboudouk closed 7 years ago

sboudouk commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

+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 commented 8 years ago

@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 commented 7 years ago

@phadej can we include this patch?

phadej commented 7 years ago

The #14?

0o-de-lally commented 7 years ago

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