
This is @ryusei__46 here.
This time, I had quite a tough time building native modules with NW.js, so I want to document this as a reference.
With Electron, you could easily handle this with the convenient "electron-rebuild" module, but NW.js has some peculiarities.
While Electron is by far the most well-known native app framework, I recently stopped using it. The reason? Lack of source code protection functionality. Exposing your code is inherently insecure, and it leaves it vulnerable to code theft.
Alright then, let's quickly walk through rebuilding native modules with NW.js.
My Environment
- Windows 11 Pro
- node.JS v18.13.0
- node-gyp v9.1.0
- node-pre-gyp v0.17.0
- nw v0.72.0
- nw-gyp v3.6.6
- sqlite3 v5.1.3
Rebuild native modules
Recently, when developing a native app individually, I had the opportunity to use SQLite and decided to adopt the "sqlite3" module. Since this is a native module, it requires rebuilding when using it with NW.js.
-- project root
|--- node_module
|~~~ src // source and files
|=== build // Distributed pre-built packages
|=== package.jsonCommandline Copy
We develop our applications using the following structure. First, install the Sqlite3 module via npm:
npm i sqlite3 --save
Next, install the npm packages required for rebuilding.
npm i node-gyp node-pre-gyp nw-gyp -g
For best results, use the "-g" option to perform a global installation.
After installation is complete, you'll need to rebuild the "Sqlite3" package you just installed. Unlike with Electron, you'll need to navigate into the project directory of the module you want to rebuild. This means:
- Change directory ("cd") into the "Sqlite3" project directory located at `project_root\node_modules\sqlite3
`
- Rebuild "sqlite3" for NW.js using "node-pre-gyp"
cd .\mode_module\sqlite3
node-pre-gyp rebuild --runtime=node-webkit --target=0.72.0
--target_arch=x64
These are the options to use with node-pre-gyp: leave "–runtime=node-webkit" as is, and specify the current NW.js version number for "–target=x.x.x". For "–target_arch=x64", enter the architecture type of your PC - for Windows 64-bit OS, the default setting should work.
This should allow you to perform the rebuild successfully.
Reference Site

概要 node-webkit使ってシリアルポート経由で、arduinoが送ってくるカラーセンサーの値を読もうとしたらserialportモジュール入れるのに苦労した。ので、対処したときの記録。もしかすると必要ないものとか、手順もあるかもしれない。 もっと簡単な方法とかあっ...
Environment: Linux 5.0.11-1.el7.elrepo.x86_64 node v15.6.0 node-gyp v7.1.2 (installed globally) Python version 2.7.5 Full Log $ node-gyp rebuild gyp info it worked if it ends with ok gyp info using...