Project install error node_modules\node-sass: Command failed. Solution

When installing packages and related dependencies in the company's previous projects, the error node_modules\node-sass: Command failed was reported.

I tried all the methods on the Internet, such as switching Taobao mirrors, but it didn't work. After struggling for a long time, I finally asked my colleagues and found out that it was a problem with the node.js version. The node.js version used in this project is 12.22.12, which is incompatible with the 16.18.1 I am currently using.

The solution is to switch to the corresponding node.js version . You can uninstall the current version and reinstall the version required by the project.

Check the node version required by the current project

If the project uses yarn and typescript, you can check the version of @types/node@ in yarn.lock (it is useful for personal testing). You can also ask colleagues who have worked on this project before (this is the most effective)

 Other methods are not used yet:

  • packageJson.engines, third-party modules will all have them, and your own projects may have them.
  • pm2.app[].interpreter, if deployed  pm2 , you can view the interpreter option, but there is no guarantee that this item exists
  • FROM, if deployed  docker , check  Dockerfile the version number of the node in the base image

However, it is also very inconvenient to switch node versions frequently. In this case, you can use nvm, a nodejs version management tool! To do versioning use control.

1. Download nvm and install it, nvm official website address 

Note: When selecting the nvm installation path, do not have Chinese characters or spaces  in the folder name.

2. Run as administrator and enter nvm. If the icon appears, the installation is successful.

 3. nvm command

  • nvm list command - displays version list
nvm list // 显示已安装的版本(同 nvm list installed)
nvm list installed // 显示已安装的版本
nvm list available // 显示所有可以下载的版本
  • nvm install command - install the specified version of nodejs
nvm install 14.5.0 // 安装14.5.0版本node
nvm install latest // 安装最新版本node
  • nvm use command - use the specified version node
nvm use 14.5.0 // 使用14.5.0版本node
  • nvm uninstall command - uninstall the specified version node
nvm uninstall 14.5.0 // 卸载14.5.0版本node

Reference article:

https://blog.csdn.net/qq_34373197/article/details/122809786

https://www.jianshu.com/p/13c0b3ca7c71

Guess you like

Origin blog.csdn.net/Heixiu6/article/details/128111918