Domestic do front-end, I feel mostly by this pit, all the dependence are installed on, only this dependence on how can not be installed.

In fact, the biggest reason why this dependency cannot be installed is that it needs to download an installation package when compiling and installing. This installation package is on Github. Due to unexplicable reasons, it is difficult to connect to github resource server RawgithubuserContent in China. This also leads directly to dependencies not being installed.

Solution 1: Taobao mirror, is also the most direct solution, Taobao mirror node-sass installation package address has been changed to taobao mirror installation package address, installation will be very smooth. This is also the official solution to the network problem.

npm install -g mirror-config-china --registry=http://registry.npm.taobao.org
npm install node-sass
Copy the code

Again — Registry or CNPM is suitable for this solution.

Solution 2: Some people may not be able to download packages from Taobao images directly because the team uses package-lock.json to standardise the dependencies used by the team, but there is a solution: manually specify the installation package address for Node-sass. Through NPMRC:

npm config set sass_binary_site "https://npm.taobao.org/mirrors/node-sass/"
Copy the code

You can also set environment variables:

set SASS_BINARY_SITE=https://npm.taobao.org/mirrors/node-sass/
Copy the code

In this way, you can also use taobao image to download the installation package directly through NPM install.

Solution 3: If you can specify the download path, you can also download the installation package first and then specify the installation package for installation. Go to https://github.com/sass/node-sass/releases/tag/ {version} or download the corresponding installation package: https://npm.taobao.org/mirrors/node-sass/ {OS}-{module-version}_bingding.node. The specific version can be found in the following table according to your nodejs version.

NodeJS Supported node-sass version Node Module
Node 15 5.0 + 88
Node 14 4.14 + 83
Node 13 + 4.13, < 5.0 79
Node 12 4.12 + 72
Node 11 + 4.10, < 5.0 67
Node 10 4.9 + 64
Node 8 4.5.3 +, < 5.0 57
Node <8 < 5.0 < 57

The next steps are similar to method 2, where the NPMRC modification is given

npm config set sass_binary_path [path]
Copy the code

Solution 4: Since the main reason is kung Fu Net, you have to turn over the past. Set up the system agent first, then configure the NPM agent.

npm config set proxy [system proxy]
Copy the code

Once the download is complete, the problem is only half solved. The downloaded installation package still needs to be compiled, and Node-sass needs some compilation environment to ensure that the compilation is complete. Here is a simple solution:

npm install -g node-gyp
npm install --global --production windows-build-tools
Copy the code

This will help you install the appropriate build environment and most of the problems will be solved. It includes the VS build tool and Python.

If your Node-gyp is not installed globally, but is a dependency in package-lock.json, it is a good idea to check the node-gyp version. For example, in my case, node-gyp is restricted to an older version. The biggest problem is that node-gyp itself decides which build version it calls. Some older versions of Node-gyp do not support later builds. The corresponding support can be found in version_map in msvsversion.py of Node-gyp, as in my 3.8.0 example:

  version_map = {
    'auto': ('14.0'.'12.0'.'10.0'.'9.0'.'8.0'.'11.0'),
    '2005': ('8.0',),
    '2005e': ('8.0',),
    '2008': ('9.0',),
    '2008e': ('9.0',),
    '2010': ('10.0',),
    '2010e': ('10.0',),
    '2012': ('11.0',),
    '2012e': ('11.0',),
    '2013': ('12.0',),
    '2013e': ('12.0',),
    '2015': ('14.0',).}Copy the code

As you can see, this only supports VS2015 at most, so I manually installed the BUILD tool for VS2015 to compile successfully. You can also manually specify msvs_version to build the version of the tool, but auto will suffice in most cases.

npm config set msvs_version [version]
Copy the code

If there is a problem, you are welcome to share the error log output to see if there are any other hidden pits in it.