Due to some undescribable reasons, a package download failure occurs when installing modules using NPM, especially node-sass. In other words, the binary file of Node-sass is close to 100% failure. The following suggestions are given even when installing modules using YARN

Method 1

First of all, we need to download the binary file of Node-sass in advance, which can be downloaded from CNPM warehouse or Github of Node-sass. Before downloading, we need to check the version of computer system to determine which version of binary file is suitable. The command to check the version is as follows:

node -p "[process.platform, process.arch, process.versions.modules].join('-')"
Copy the code

Enter this command to pop up a system version, and choose one of the following two addresses to download the node-sass file with the.node suffix for the system version

cnpm https://npm.taobao.org/mirrors/node-sass/(opens new window)

github https://github.com/sass/node-sass/releases

Once downloaded, save to any location, preferably package.json. Then we need to manually specify the download source of the Node-sass binary file as the downloaded file. Here are the NPM and YARN instructions:

npm

NPM config set sass-binary-path e:/web/win32-x64-48_binding.nodeCopy the code

yarn

Yarn config set sass-binary-path The directory where you stored the downloaded binary file // for example, yarn config set sass-binary-path e:/web/win32-x64-48_binding.nodeCopy the code

Then we can use the normal instructions to download

Pay attention to

This method is bound to a local file, meaning node-sass cannot be updated. If you don’t want this, use the second method

Method 2

This scenario designates the download source as the CNPM repository, which is preferred

All download sources point to CNPM instructions

npm

npm config set registry http://registry.npm.taobao.org
Copy the code

yarn

yarn config set registry http://registry.npm.taobao.org
Copy the code

Specify only the node-sass download source (recommended)

npm

npm config set sass-binary-site http://npm.taobao.org/mirrors/node-sass
Copy the code

yarn

yarn config set sass-binary-site http://npm.taobao.org/mirrors/node-sass
Copy the code