未找到节点模块“nw.gui" [英] node module 'nw.gui' not found

查看:32
本文介绍了未找到节点模块“nw.gui"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我要运行的代码

//global.$ = $;var abar = require('address_bar');var folder_view = require('folder_view');var path = require('path');var shell = require('nw.gui').shell;

这就是我得到的:

module.js:340抛出错误;^

<块引用>

错误:找不到模块nw.gui"

at Function.Module._resolveFilename (module.js:338:15)在 Function.Module._load (module.js:280:25)在 Module.require (module.js:364:17)在要求 (module.js:380:17)在对象<匿名>(/home/parisa/Documents/nw-sample-apps-master/file-explorer/main.js:6:13)在 Module._compile (module.js:456:26)在 Object.Module._extensions..js (module.js:474:10)在 Module.load (module.js:356:32)在 Function.Module._load (module.js:312:12)在 Function.Module.runMain (module.js:497:10) 程序退出.

我无法获取此模块.我该怎么办?

解决方案

nw.gui 是一个 NW.js(以前称为 node-webkit)模块.当您的代码在其运行时环境中运行时,NW.js 应提供对它的访问.

从您的错误消息来看,我假设您是直接通过 NodeJS 运行该文件的.要运行 NW.js 项目,您需要通过 NW.js 可执行文件加载它,其中包括 NodeJS.您可以通过多种方式执行此操作,如如何运行应用程序"页面所述:

找到包含 package.json 文件的项目文件夹.通过压缩整个文件夹来运行它,将文件扩展名更改为.nw",然后运行以下命令:

nw/home/path/to/packagedapp.nw

或者,直接在文件夹上运行命令:

nw/home/path/to/appdir/

您可以为此创建一个快捷方式以使其更容易.最终,您可以将 NW.js 可执行文件与您的代码合并为一个可执行文件,请参阅 如何打包和分发您的应用.

<小时><块引用>

从 node-webkit 内部运行它,仍然没有找到nw.gui",有什么线索吗?

也许您正试图从节点上下文"中访问 nw.gui,而 Node 抱怨找不到它.

NW.js 中的 Javascript 可以在 Node 上下文中运行(就像在 NodeJS 中简单地运行代码,使用所有 NodeJS 全局变量)或浏览器上下文"(也可以访问浏览器,使用 窗口 全局变量).节点上下文只能访问节点内容,但浏览器上下文可以访问两者.

网页中包含的代码在浏览器上下文中运行,但 require()d 的代码在节点上下文中执行.请参阅文档JavaScript 上下文的差异..>

This is the code I want to run

//global.$ = $;

var abar = require('address_bar');
var folder_view = require('folder_view');
var path = require('path');
var shell = require('nw.gui').Shell;

and this is what I get:

module.js:340 throw err; ^

Error: Cannot find module 'nw.gui'

at Function.Module._resolveFilename (module.js:338:15)

at Function.Module._load (module.js:280:25)

at Module.require (module.js:364:17)

at require (module.js:380:17)

at Object.<anonymous> (/home/parisa/Documents/nw-sample-apps-master/file-explorer/main.js:6:13)

at Module._compile (module.js:456:26)

at Object.Module._extensions..js (module.js:474:10)

at Module.load (module.js:356:32)

at Function.Module._load (module.js:312:12)

at Function.Module.runMain (module.js:497:10) Program exited.

I can't get this module. what should I do?

解决方案

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.

这篇关于未找到节点模块“nw.gui"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆