5

I have a package.json file that looks like:

{
    "name": "title",
    "description": "description",
    "version": "0.1",
    "main": "https://path-to-application/",
    "window": {
        "show": true,
        "toolbar": false,
        "frame": true,
        "position": "center",
        "width": 800,
        "height": 600,
        "min_width": 220,
        "min_height": 220
    }
}

But when I attempt to run the code:

var GUI = null;
var win = null;
try { GUI = require('nw.gui'); win = GUI.Window.get(); } catch (ex) { }
win.toggleFullscreen();

Nothing happens, adding alerts for GUI and win show they are both set to null. When I run the same code from an index.html file within the same .zip as package.json it works as expected. It appears to be failing with the initial call to require().

Is there some way to get this working in a remotely hosted application?

CoryG
  • 2,429
  • 3
  • 25
  • 60
  • 1
    Did you try to actually catch any exception and see what it says? The reason they weren't set in the try block probably threw an exception. – orb Mar 25 '13 at 04:39
  • The error is: "ReferenceError: require is not defined". – CoryG Mar 25 '13 at 05:42

1 Answers1

6

I was able to solve this following by adding the node-remote field to the package.json file if anyone else runs into this issue.

CoryG
  • 2,429
  • 3
  • 25
  • 60
  • that's great ... do you know if it's possible to host the node_modules remotely too. I can only get it to work if my node_modules are inside the app folder that I use to create the node-webkit exe. It would be amazing if we could pull those remotely too so I can update dependencies remotely with having to release a new version of the app. – stukennedy Jun 20 '14 at 16:26
  • @CoryG Can you show your package.json file? The node-webkit wiki doesn't make the node-remote instructions immediately obvious. – NetOperator Wibby Sep 19 '14 at 13:43
  • Can you give an example of the rules you used? I can't seem to get it to work. – drwatsoncode Feb 24 '15 at 21:01
  • in the root of the package.json file (in the example above put it above the line saying `"window": {` add the line `"node-remote": "https://path-to-application/",` – CoryG Feb 26 '15 at 16:16
  • Edited to add in a complete example :) – Jaymes Bearden Mar 04 '15 at 21:18