Electronic 7.0.0 installation failed

Time:2019-11-8

The first time I experienced electron, I encountered the problem that the installation has not been successful. I have tried the online method basically, and the summary is to switch the source. But basically only settingsELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/", yes, in the previous version, only this can be set. but7.0.0No, look at my failure process and solution process.

Official website example

#Clone this repository
git clone https://github.com/electron/electron-quick-start
# Go into the repository
cd electron-quick-start
# Install dependencies
npm install
# Run the app
npm start

It’s not going to work. It’s stucknode install.jsHere

Electronic 7.0.0 installation failed

I tried the online method, but I couldn’t. Last to see the source code, first on my solution.

Resolvent

installcross-env, to set environment variables (settings) for subsequent commandsproccess.env)You can also set the system environment variables yourself without installing this

Under the update, the new version is already7.0.1Yes, if you’re using7.0.1, note change tocross-env npm_config_electron_mirror="https://npm.taobao.org/mirrors/electron/" npm_config_electron_custom_dir="7.0.1" npm install, i.enpm_config_electron_custom_dirTo set as version number`**

#Install cross Env, note global installation
npm install -g cross-env
#Clone this repository
git clone https://github.com/electron/electron-quick-start
# Go into the repository
cd electron-quick-start
# Install dependencies
cross-env npm_config_electron_mirror="https://npm.taobao.org/mirrors/electron/" npm_config_electron_custom_dir="7.0.0" npm install

Successfully installed (this screenshot shows that it was not installed previouslycross-envInmacResults on the computer)

Electronic 7.0.0 installation failed

npm start

Electronic 7.0.0 installation failed

Solving process

Get intonode_modulesIn the folderelectronFolder, open the insideinstall.jsfile

Electronic 7.0.0 installation failed

SeedownloadArtifactDefinition of function, insidegetArtifactRemoteURLGet the remote download address, which can be downloaded throughlogPrint it out and check it, so you can see why it can’t be downloaded

Electronic 7.0.0 installation failed

Add a print, view the download address, enter the printed address into the browser, and view the results, you can see that it is really difficult to download

Electronic 7.0.0 installation failed

This is how to change the source onlinenodeAdd parameters before the command to set the currently runningprocess.envThe value in (as shown in the following code)

ELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/" node install.js

Electronic 7.0.0 installation failed

It still can’t be downloaded. The printed website is https://npm.taobao.org/mirrors/electronic/v7.0.0/electronic-v7.0.0-darwin-x64.zip, which is compared with the available source address. It is found thatv7.0.0More than one.v, the following figure is the source map that can be downloaded

Electronic 7.0.0 installation failed

Let’s see how the download address is generated. CheckgetArtifactRemoteURLFunction, as follows

Electronic 7.0.0 installation failed

It can be seen frombase, path, fileThe default parameters for splicing are as follows

Electronic 7.0.0 installation failed

Can be set byprocess.envTo modifybasepathfile, the setting method is as followsnodenpmAdded before commandkey-valueValue. As amendedbase, add before command lineELECTRON_MIRROR="https://npm.taobao.org/mirrors/electron/"Set up baseOfkeyIt can be written.ELECTRON_MIRROR, can also be written asnpm-config-electron-mirror, (see code for other forms). Let’s see.pathByversionDecide orprocess.envLinpm-config-electron-custom-dir(in many forms), thisversionOriginateelectronUnder folderpackage.jsonFile, you can see yes7.0.0

Electronic 7.0.0 installation failed

Electronic 7.0.0 installation failed

Why there are morevGo backdownloadArtifactFunction, you can see the code addedv

Electronic 7.0.0 installation failed

Electronic 7.0.0 installation failed

So to get the right source, set it yourselfprocess.envLinpm-config-electron-custom-dir

Other methods, such as downloading offline packages from https://npm.taobao.org/mirrors/electronic/7.0.0/, putting them in the cache location, setting the cache, etc., can be seen in the code setting parameters

Take a look at the default parameters of different platforms, pure solution

Electronic 7.0.0 installation failed