Electron installs node native module (sqlite3) under windows--stepping pit record

What is more disgusting than not being able to write code is that there is a problem with the environment configuration, and the written code cannot run. Install sqlite3 directly in electron under widows, when calling, it will prompt that the sqlite module cannot be found. It seems simple, but there is no hint. The domestic online information is incomplete, and most of them are copied from each other. It has been stuck for nearly a week, and Baidu and Google have turned to rotten. Finally, the compilation was successful today, so I recorded this process, hoping to give others some solutions.

installation steps

1. Install vs2015!

The c++ environment for compilation is included in vs2015

ed2k://|file|cn_visual_studio_community_2015_x86_dvd_6847368.iso|4013920256|EB7F6605EDE67509E218E29173AC6574|/

This is the Chinese version of Visual Studio Community 2015. Install the C++ related ones. After installation, open vs2015--"File--"New--"Project

Select the C++ blank template, if the environment is not fully installed, it will prompt to install the rest, install it all! !

2.python 2.7

Download from python official website. Must be 2.7, 3.X does not support.

Remember to tick Set environment variables during installation.

3. Install cnpm

cnpm is recommended for wall cracks to avoid all kinds of ETIMEOUT. Sometimes it can't be solved by changing the source.

4. Install sqlite3

The foreplay is over, let's get to the point. First, confirm the current electron version

"scripts": {
     ...
    "ev": "electron --version"
 }

Run the electron --version command. To save trouble, I added it to package.json, which is used by npm run ev.

My version is 1.7.11

run

 cnpm install sqlite3@latest --build-from-source --runtime=electron --target=1.7.11 --dist-url=https://atom.io/download/electron --save

Note that after target is the version number of your current electron

The basic operation is completed here. The next step is to pray and wait (2~3mins). If you are lucky, it will pass, if you are not, it will be full of errors.

Common error log

Below are the various errors I've encountered, no screenshots at the time, only descriptions now. Just remembered these

  1. node-gyp installation, this is relatively simple, pay attention to the need to install the environment in advance under windows (vs2015)
  2. Pay attention to the error prompt, sometimes it will prompt that python cannot be found at the beginning, and you need to set environment variables .   But Nima, my environment variable is written on it! I am also drunk. No setting can work. Finally, python was uninstalled and reinstalled, and this error was not reported. (If python has multiple versions, you need to set the version. For details, search the node-gyp package)
  3. Error   #npm install# MSBUILD : error MSB4132: Unrecognized tool version "2.0". The available tool version is "4.0". Don't say anything, go and install vs2015.
  4. Error fatal error C1083: Unable to open include file: "node.h" . This error turned out to be because the system username must be in ASCII code. I wrote a Chinese username at that time, which stuck me all night.

refer to

I came across two more valuable blogs, which provided me with a great reference

  1. A project using the electron-vue template, but following it to install sqlite3 failed https://segmentfault.com/a/1190000010740918
  2. The installation and use of sqlite3, the method I used is completed in accordance with this article, but the process of installation failure is briefly mentioned, I am a kind of completion after stepping on the pit   https://newsn.net/say/electron -install-sqlite3.html

 

After a week of torment, this pit was finally resolved. But I already have a hunch that there will be a bigger pit when packing. Every day is tossing, irritable

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325062714&siteId=291194637