'Why do I need Visual Studio and C++ to install node modules

Recently I have upgraded my node version to 14+ from 10+ in a Vue.Js app. But It was giving me some error and asking to install Visual Studio including C++. When I installed VS with C++. It started working great. But after that whenever I do a fresh "npm install" It requires C++. It doesn't seem normal. What is the relation between node and C++. I thing there is something what I am missing. If anyone know the solution please let me know...

I have mentioned where the app is using C++ down bellow.

> [email protected] install G:\PROJECT_PATH\node_modules\node-zopfli-es

> node-gyp rebuild


G:\PROJECT_PATH\node_modules\node-zopfli-es>if not defined npm_config_node_gyp (node "C:\Users\pc\AppData\Roaming\nvm\v14.17.0\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Users\pc\AppData\Roaming\nvm\v14.17.0\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.

zopfli-binding.cc

zopflipng.cc

zopflipng_lib.cc

lodepng.cpp

......


Solution 1:[1]

This is quite normal with certain types of node.js packages. A lot packages have binary dependencies to improve performance (or just to integrate with a pre-existing library like zopfli). Instead of the project maintainers distributing a ton of different binaries for different architectures and versions of operating systems they tend to supply the source and let it be built when installed.

This is usually handled by node-gyp which is also featured in your build log but it in turn requires the correct build tools to be available on the system, in most cases a C/C++ compiler and in quite a few cases Python as well.

For older versions of node.js you could use the windows-build-tools-package to install the needed dependencies (you won't need a full Visual Studio for example, just the build tools) but in newer versions of the nodejs installer (for Windows at least) this is an option when installing.

Node.js setup showing the page on which native modules tools can be selected

If you missed that setting when installing you can still use the above package to install them.

Solution 2:[2]

I have come across the same problem and had to install Visual Studio 2019 and Python for the project to work.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Karl-Johan Sjögren
Solution 2 zurik_ned