最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using require() in a remotely-hosted node-webkit application - Stack Overflow

programmeradmin2浏览0评论

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?

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?

Share Improve this question asked Mar 25, 2013 at 3:24 CoryGCoryG 2,5914 gold badges30 silver badges64 bronze badges 2
  • 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 Commented Mar 25, 2013 at 4:39
  • The error is: "ReferenceError: require is not defined". – CoryG Commented Mar 25, 2013 at 5:42
Add a ment  | 

1 Answer 1

Reset to default 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.

发布评论

评论列表(0)

  1. 暂无评论