node module 'nw.gui' not found

前端 未结 1 880
北海茫月
北海茫月 2020-12-19 16:41

This is the code I want to run

//global.$ = $;

var abar = require(\'address_bar\');
var folder_view = require(\'folder_view\');
var path = require(\'path\')         


        
相关标签:
1条回答
  • 2020-12-19 17:12

    nw.gui is a NW.js (previously called node-webkit) module. NW.js should provide access to it when your code is run from within its runtime environment.

    By the look of your error message, I assume you're running the file directly via NodeJS. To run a NW.js project you need to load it via the NW.js executable, which includes NodeJS. You can do this a few ways, as described in the "How-to-run-apps" page:

    Find the project folder, which contains the package.json file. Either run it by zipping the whole folder up, changing the file extension to ".nw", and running the command:

    nw /home/path/to/packagedapp.nw

    Or, just run the command straight on the folder:

    nw /home/path/to/appdir/

    You can make a shortcut for this to make it easier. Eventually you can combine the NW.js executable with your code into a single executable, see How to package and distribute your apps.


    Running it from inside node-webkit, still not finding 'nw.gui', any clue?

    Maybe you're trying to access nw.gui from within the "Node context", and Node is complaining that it can't find it.

    Javascript in NW.js can be run in Node context (which is like simply running the code within NodeJS, with all the NodeJS globals) or "Browser context" (which also has access to the browser, with the Window globals). Node context only has access to node stuff but the browser context has access to both.

    Code that is included from a web page runs in browser context but code that is require()d gets executed in node context. See the document Differences of JavaScript contexts.

    0 讨论(0)
提交回复
热议问题