SQLite and NW.js - step by step instructions for creating a strong friendship

    Hi, Habr and its inhabitants! I wanted to sculpt something on HTML and JS, so that it was desktop and convenient. What is needed for this? Right. Node.js and NW.js or Electron. Looking at the weak attempts of holivar NW vs Electron and after reading the documentation of both of them, it was decided to start to touch NW.js.

    But here's an ambush. Execution npm i sqlite3installs only those libraries that can be executed by running directly through the node. And if you try to connect the script in html and run this html in NW.js, then nothing will come of it. Google associates give out only one recipe for including sqlite in a project on nw.js, and that one has to be pulled out of the cache. Yes, and it is outdated. Therefore, it took a couple of days to study the problems and find a working solution. I ask under the cat.

    So. To begin with, a machine “from what it was” was assembled and Windows 7 x32 with .NET 4.7.1 package installed (required for Visual C ++). Why 32 bits? I decided to start small. Although, as it turned out, the creation of a module for x64 does not require execution on the x64 system.

    Then Node.js version 10.8.0 was delivered. Although at the end of the experiments 10.9.0 had already appeared. But then I decided to listen to knowledgeable people:

    Pondering, I decided that I’m still doing it for the LTS, although it’s not entirely clear where all LTS have them and where they don’t. Assumed that non-LTS - is beta, alpha and nightly build.

    Although, like any dropout, I did everything in half and did not fulfill the following recommendation:

    Recommendation from LTS-releases documentation
    On Windows, you need to replace the file
    node with the node at the github.com/nwjs/nw.js/blob/nw18/tools/win_delay_load_hook.cc before installing modules with node-gyp or npm.

    Well, I did not find this file on my computer. Probably because I did not install node-gyp.

    For the node set (it is imperative to do from the command line with administrator rights)

    npm i -g nw-gyp

    In fact, the replacement node-gyp
    NW-GYP to support NW.js specific headers and libraries.

    Next - download Visual Studio Community Edition (the current link is easily found in your favorite search engine) - as of this writing, the current version is 2017. What is important for us is it contains Build Tools 2015 - while the native modules in the node are only assembled with this version and more fresh do not support. Download the installer, run and put one tick in the tab “Individual Components” - VC ++ 2015.3 v14.00 Toolkit (v140) for PC The added Windows 8.1 SDK is also needed, therefore we install all three items. Installation in this form leads to a jump of 2.89 gigabytes of all necessary. Going further - swing the snake. Moreover, version 2.7. Set by default in C: \ Python27. And now - attention! Ambush.

    The default installer believes that it is not necessary to add the location of the python to PATH, so we eliminate this misunderstanding during the installation phase.

    A similar ambush haunts many developers when building a variety of modules for a node. And all because the small-scale corporation also does not consider it necessary to prescribe paths to their creations. The githab is simply overwhelmed with assembly errors due to the fact that after installation, the path to the assembly tools is not included in the PATH. We also correct this misunderstanding - we correct the environment variable so that it allows the assembly to go through, if not very smoothly, then at least without errors. That's what I got (broken into lines for better perception) Bold is what needs to be added manually. Naturally, making sure that these paths exist. Mandatory item -

    >echo %PATH%
    C:\Program Files\nodejs\;
    C:\Program Files\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin;
    C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\v140;

    reboot .

    Well, now the actual assembly. I used the FAR manager, but no one forbids the old-school cmd for x64 to change --target_arch = x64. Well, that's all. If everything is done correctly, the assembly passes with a certain number of messages of the type, but as a result, the module is assembled and placed in the Assembly Nuance - with each assembly the node_modules / sqlite3 / lib folder is deleted by the builder. Therefore, if there is a need to assemble two modules (for each architecture), save the intermediate result. Thank you for your attention, and finally, the result of the experiment: Assembled modules for NW.js 0.32.1 ia32 && x64 on Google Disk

    md app
    cd \app
    npm init
    npm install sqlite3 --build-from-source --runtime=node-webkit --target_arch=ia32 --target=0.32.1 --msvs_version=2015

    ..\src\database.cc(672): warning C4996: 'Nan::MakeCallback': объявлен deprecate [C:\app\node_modules\sqlite3\build\node_sqlite3.vcxproj]
    C:\app\node_modules\nan\nan.h(929): note: см. объявление "Nan::MakeCallback"
    c:\app\node_modules\nan\nan_new.h(208): warning C4244: аргумент: преобразование "sqlite3_int64" в "double", возможна потеря данных (компилируется исходный файл ..\src\database.cc) [C:\app\node_modules\sqlite3\build\node_sqlite3.vcxproj]


    Also popular now: