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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…