Wednesday 24 July 2019

My story of getting node-gyp to work on windows (TL;DR: --target=8.16.0)

​You start off my finding this cool node module you want to install for your electron app on windows but see that it requires something called 'node-gyp'. After a quick run through duckduckgo you end up on the github page of node-gyp and read through the README file. It was not long before you grasp the meaning of node-gyp.This magical module seems to solve a problem you never thought you would face. The requirements were heavy but someone made an easy tool to install everything with just one command. "Thank god", you think to yourself, and decide to quickly open an elevated git bash terminal to type 'npm install --global windows-build-tools'.The program starts, cog wheels begin to turn and everything gets installed for you without you doing anything.Time passes and you see that the program has finished. After a quick reboot you finally get to the fun part and install the module you wanted from the beginning.C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe\ failed with exit code: 1...After a long wall of red text you find this message engraved inside the terminal. In quick programmer fashion you pull up duckduckgo and search for 'node-gyp msbuild failed with exit code: 1'.It was by then that you started to be skeptical about everything just being a one liner. The internet was full of posts about node-gyp producing errors on windows and most of them were old, most before windows-build-tools existed. "I probably missed something" is what you thought. Starting to trace back the error, you find ~300 errors of node-gyp trying to compile the module you want to install. With increasing hate for the non-informative logs and posts of node-gyp you decide to end the day.The next day:With a fresh mind and body you again try to tackle the problem. This time you don't rely on some one line command tools but install the requirements for node-gyp manually.Two hours pass:C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe\ failed with exit code: 1"Something isn't right.". Your spider senses tell you that the multiple versions of Visual Studio, Visual Studio Code, and mutliple compiler for everything may have screwed the program a bit. After booting your second development environment on a linux virtual machine you try developing your electron app in linux only to be greeted with the obvious error that the node module you wanted the whole time is for windows only."Do I really need this module?", was the first question that popped into your mind after wasting nearly two days trying to get this to work. The module was a wrapper for a dll that exposes functions of a program.Two days later:You spend the last two days experimenting with different methods to access the dll:You start with the language you're the most knowledgeable with, Java, and discover JNI and latter JNA. Your mind starts going towards the crazy side when you have to deal with stuff you never heard like "Pascal" and "Delphi". "What the hell is a Delphi", "What does Delphi have to do with Pascal", "Why is everything for Pascal 10 years old", "Are you telling me someone named their IDE after the language?", "..."The days get hotter and longer. It's 35 outside and 30 inside. Creating your own DLL wrapper will take too long. "Guess I back to node-gyp". You begin using your fried brain, 10 mugs of coffee and the Initial D - Eurobeat playlist to get node-gyp to work. And than...."Wait, everyone on the forums and github uses msbuild 2013/2015. Maybe I should try that.". While installing older versions you find the arguments for node-gyp and decide to experiment during the wait.It was then when you found the one line that changed everything:gyp verb get node dir compiling against --target node version: 12.6.0You can change the target node version for compiling. Just for fun you decide to run with --target=8.0.0 because you saw that this was the version before node10.Build succeeded.Wait WHATTTT. You stopped everything you've been doing and looked at the log.``` 2 Warning(s) 0 Error(s)Time Elapsed 00:00:04.69 gyp info ok ```It worked. You quickly find out that 10.16 also doesnt work and the latest version that does is 8.16.0. You've done it. Five days of intense mental pain, stress and wanting to cease existing you finally compiled the module and can work on the actual program.Authors note: Man. I somewhat had to rush the story in the end (starting at the Two days later mark) because I want to finally start working on the project. I tried a ton of methods to get what I want and the solution was just one argument away from saving me 5 days. Anyway.. I didnt spellcheck this but I just wanted to share this little story. I don't even know if the mods allow this post, if fun is allowed, but I want to try anyways. :)

Submitted July 24, 2019 at 06:54PM by _erri120_

No comments:

Post a Comment