I have a problem with loading node-modules in my node-webkit application.
For example module usb
(https://npmjs.org/package/usb).
It was successfully installed from npm (npm install usb --save-dev
) and works in simple Node.js, also it was successfully rebuilded by nw-gyp
for using in node-webkit.
I don't include node_modules
folder in my app.nw
, so after building using grunt, I have a following structure of files:
When I try to load this module in my appliacation, using following code:
var usb = require('usb');
I get an error
Error: Cannot find module 'usb'
Why node-webkit can't load this module?
p.s. All default modules like path
, url
, http
works.
In my case the problem has two reasons:
If I want to use node modules, which written on C++, I can't give for my app custom name (in my case 'app'), I should use default name 'nw'. https://github.com/rogerwang/node-webkit/wiki/Using-Node-modules#3rd-party-modules-with-cc-addons
As I understood, it's not possible to load modules into appliacation from external folder 'node_modules' using function 'require'.