The issue:
When trying to npm install something on Windows through Administrative PowerShell or CMD, you can sometimes encounter an error with something about “Microsoft.cpp”, which might help solve your issue. I was trying to install the Sleep module into my Node.js program, and it failed with exit code 1, as seen below. The solution was installing Python and Visual Studio Build Tools, with the commands at the bottom of the page.
Steps to solve the issue (Installing Python and Visual Studio Build Tools):
- Open Administrative PowerShell.
- Run the command
Set-ExecutionPolicy Unrestricted -Scope CurrentUser -Force - Run the command
npm install -g windows-build-tools - Once this is completed (Mine took 527.484 seconds - 8.79 minutes)
- Now the installation should be okay with everything, and everything should be working.
Below is a picture of the solution after it’s complete.
What does the “Microsoft.cpp” error mean?
The error you’re seeing usually contains a line that points at a file like C:\...\node_modules\xxx\node_modules\node-gyp\... and a reference to MSB8020 or MSB8003, or a fatal error C1034 / C1189 from a Microsoft.cpp header. The build is invoking Microsoft’s C++ compiler (cl.exe) and that compiler is rejecting the build.
In plain English: the npm package you tried to install contains native C or C++ code, and your machine is missing the Visual Studio C++ build tools that Microsoft’s compiler needs. node-gyp (the tool npm uses to build native modules) drove the build into MSBuild, which then called the C++ compiler, which then failed because either the compiler itself or the Windows SDK headers aren’t installed.
“Exit code 1” is just the build script’s way of saying “the compiler returned a non-zero status, which means failure.” It doesn’t tell you what failed - you have to read the lines above it. Look for error MSB (MSBuild) or error C (the C++ compiler) for the actual reason.
Why does node-gyp need MSVC build tools?
node-gyp exists because some npm packages - anything that needs to be fast, low-level, or talk directly to the OS - include compiled C/C++ code in a .node file (a native Node addon). The source for that file ships in the npm tarball, and at install time it has to be compiled against the exact Node.js version and ABI on your machine. Linux and macOS ship with a working C compiler by default. Windows does not, which is why the extra step is needed.
The compiler required is specifically the MSVC (Microsoft Visual C++) toolchain. You cannot use MinGW or GCC - node-gyp’s build system is hard-wired to MSBuild, the Windows-specific build tool that comes with Visual Studio Build Tools. If you try to point it at gcc it will fail with a much more confusing error.
The windows-build-tools deprecation note
Like the Python fix, windows-build-tools is officially deprecated. It still works on most setups, which is why this guide is still useful, but the package is no longer being updated and is known to break on the latest Node.js and Windows combinations. The deprecation notice in the package’s own README points users at:
- Installing Visual Studio Build Tools directly from Microsoft.
- Installing Python 3 from python.org separately.
- Following the node-gyp installation guide for up-to-date instructions.
If windows-build-tools fails or hangs on a modern system, the next step is to do the installation by hand. It’s not as scary as it sounds - both installers are GUI wizards.
The modern, manual way
The current recommendation is to install each component yourself:
- Download Visual Studio Build Tools from
visualstudio.microsoft.com(the free “Build Tools” SKU is enough; you don’t need full Visual Studio). - In the Visual Studio Installer, pick the “Desktop development with C++” workload. This includes the MSVC v143 toolset, the Windows 10/11 SDK, and CMake.
- From python.org, install Python 3 and tick “Add Python to PATH” in the first screen of the installer.
- Close all terminals, open a new one, and run
npm config get msvs_version. It should print something like2022. If it’s blank, set it explicitly:npm config set msvs_version 2022. - Re-run your original
npm install.
For most native modules, this is the configuration that works reliably. The build takes 1-2 GB of disk space and a one-time download of 30-60 minutes depending on your connection.
Why this is worth fixing properly
Some of the most-used npm packages in the JavaScript ecosystem are native modules. bcrypt, sharp, sqlite3, canvas, node-sass (now sass in pure JS), node-rdkafka, prisma engines, better-sqlite3, and most audio processing libraries are all native. A working MSVC + Python setup is a one-time investment that unblocks all of them, and you’ll likely run into this exact error again on a different project if you don’t fix the underlying toolchain.