- 1 year ago
running 'npm install' : Node-gyp error - MSBUILD.exe failed with exit code: 1
When running npm install
and encountering a Node-gyp error with MSBUILD.exe
failing and exiting with code 1, it often indicates an issue with building native modules on your system. Here are a few potential solutions to resolve this error:
Install Visual Studio Build Tools:
- Install the Visual Studio Build Tools, which include the necessary C++ development tools required for building native modules.
- Visit the Visual Studio downloads page (https://visualstudio.microsoft.com/downloads/) and download the "Build Tools for Visual Studio" installer.
- Run the installer and select the necessary components for C++ development. Make sure to include the MSBuild toolset.
- After installation, restart your computer and try running
npm install
again.
Set Visual Studio Version:
- If you have multiple versions of Visual Studio installed on your system, ensure that the correct version is set as the default for building native modules.
- Open a command prompt or PowerShell as an administrator.
- Run the following command to set the default Visual Studio version (replace
YYYY
with the appropriate year):arduinonpm config set msvs_version YYYY --global
- For example, if you have Visual Studio 2019 installed, use
npm config set msvs_version 2019 --global
. - Once set, try running
npm install
again.
Update Node.js and NPM:
- Ensure that you are using the latest stable versions of Node.js and NPM.
- Visit the official Node.js website (https://nodejs.org) to download and install the latest stable version of Node.js.
- Open a command prompt or PowerShell and run the following commands to update NPM:css
npm install -g npm
npm cache clean --force
- After updating Node.js and NPM, try running
npm install
again.
Check Python and MSBuild Dependencies:
- Verify that Python is installed on your system, as some native modules require it for building.
- Ensure that Python is added to the system's PATH environment variable.
- Check if the
MSBUILD.exe
executable is available on your system. If not, reinstall the Visual Studio Build Tools or Visual Studio with the necessary components. - Make sure all the required dependencies, such as Python and MSBuild, are properly configured and accessible.
Verify Permissions and Antivirus:
- Ensure that you have sufficient permissions to build and install packages on your system.
- Temporarily disable any antivirus or security software that might interfere with the build process. Some antivirus programs may block or interfere with the execution of build tools.
If the issue persists after trying these solutions, review the specific error messages and search for known issues related to the package or module you are trying to install. Check the package's GitHub repository or community forums for any reported issues or solutions.
Additionally, make sure your system meets the requirements for building native modules, such as having the necessary compilers and build tools installed. Refer to the documentation or support channels of the specific package you are trying to install for further assistance.