Run Into a NPM Node-gyp Compilation Error on Windows 10? Here’s What to Do.
If you are reading this, you probably feel alone, angry, abandoned by our society. You, however, are not alone. I’m here to walk you through this journey of frustration. You have probably looked at dozens of GitHub and Stack Overflow issues, none providing you the oasis of a compiled binary.
Let’s see what we can do to help.
The error message you are probably seeing, or some variation of it (there are many:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\x64\PlatformToolsets\v140\Toolset.targets(36,5): error
MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK vers
ion in the project property pages or by right-clicking the solution and selecting "Retarget solution".
This error can happen when you are installing a number of packages from NPM that depend on binaries being compiled in order for the package to work. One common package where this can happen is node-sass, which has native bindings that need to be compiled.
The key line is this: MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK… along with some mumbo jumbo about node-gyp.
Now, how to fix it if you are windows.
Do You Have Visual Studio Already Installed?
If you answered YES, then you need to modify your installation of Visual Studio to include the compiler for C++. Now the important thing here is to NOT INSTALL the STAND ALONE compiler. It (probably) won’t work! If you’re on 2015 or 2017, rerun the installer to modify your instance of Visual Studio and install the C++ Compiler.
If the above steps don’t work — You may need to tweak the order in which Visual Studio looks for external tools to build with.
Tools > Options > Projects and Solutions > Web Package Management
Move $(PATH) to the top of the list.
Source: https://stackoverflow.com/a/43850262/3946099 (see upvoted comment). This solution solved the problem for several colleagues.
If you run into the following error, see this Github issue thread.
I recommend switching to Node 8.x if you are on Node 10.x. That may fix it right off the bat. Otherwise, the gist is:
- Delete your node_modules folder
- Update your package-lock.json file to natives@^.1.3.
- Run npm install
gulp: ../src/node_contextify.cc:631:static void node::contextify::ContextifyScript::New(const FunctionCallbackInfo<v8::Value> &): Assertion args->IsString()' failed.
1: node::Abort() [/usr/local/bin/node]
2: node::Assert(char const* const (*) ) [/usr/local/bin/node]
3: node::contextify::ContextifyScript::New(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
4: v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo*) [/usr/local/bin/node]
5: v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<true>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/bin/node]
6: v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
If You Do Not Have Visual Studio Installed.
Well, you’re in luck. A hero named Felix Rieseberg has swooped in like a bald Eagle and saved the day with an NPM package called Windows Build Tools. You just need to do this:
npm install --global --production windows-build-tools
windows-build-tools - :package: Install C++ Build Tools for Windows using npm
That’s it! You’re good to go. Also, now you have Python.
In conclusion… You really only need to find out if you have Visual Studio installed. If you do, install the C++ compiler, otherwise run a simple NPM command to reach the pure bliss of stress-free NPM installs.