NodeJS, Windows, and trying to build ANY module (literally, pick one) - node.js

Aloha stackoverflowers. I have spent approximately 20 hours researching and attempting to build NodeJS modules under Windows 7. Research topics have included the many famous threads on node-gyp, including the "TooTallNate" threads. Most of the advice threads go something like this:
Uninstall all visual studio and vs libraries completely off the development machine
Uninstall all VS re-distributables as well just to be safe (they can be re-instaleld later).
Re-install visual studio (take your pic, the tutorials all say that vs2010, vs2012, vs2013, or express version of any of these work)
Re-install libraries (Specifically the Windows SDK 7.1 is mentioned a lot)
Launch a command prompt using the visual studio shortcut to autopopulated environment variables and path
Use the --msvs_version=vsxxxx (where xxx is the year of your visual studio version) option when building.
I have tried
VS2008 (Full)
VS2008 (Express)
VS2010 (Full)
VS2010 (Express)
VS2012 (Express)
VS2013 (Express)
I have also tried (making no difference whatsoever):
NodeJS 32-bit
NodeJS 64-bit
Apparently getting node-gyp to compile is not the issue, as "npm install node-gyp#latest -g" executes with zero warnings. I have installed NodeJS for windows.
C:\myproject\node_modules\node-hid>npm -v
2.14.3
C:\myproject\node_modules\node-hid>node -v
v4.0.0
C:\myproject\node_modules\node-hid>node-gyp -v
v3.0.3
Python is at 2.7 and I have registered it's location with npm and node-gyp
But no matter what, I am not able to compile node modules such as node-hid, keytar, etc. without receiving a multitude of various compiler errors, usually related to something it doesn't like in various .h files.
Here's my attempt with VS2013:
cd c:\myproject\node_modules\
C:\myproject\node_modules>git --recursive https://github.com/node-hid/node-hid.git
cd node-git
C:\myproject\node_modules\node-hid>node-gyp build --msvs_version=2013
\\Let the code spew begin!
gyp info it worked if it ends with ok
gyp info using node-gyp#3.0.3
gyp info using node#4.0.0 | win32 | x64
gyp info spawn msbuild
gyp info spawn args [ 'build/binding.sln',
gyp info spawn args '/clp:Verbosity=minimal',
gyp info spawn args '/nologo',
gyp info spawn args '/p:Configuration=Release;Platform=x64' ]
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
hidapi.vcxproj -> C:\my_project\node_modules\node-hid\build\Release\
hidapi.lib
HID.cc
..\src\HID.cc(51): error C3861: 'NanThrowError': identifier not found [C:\TEMP\myproject\node_modules\node-hid\build\HID.vcxproj]
..\src\HID.cc(67): warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow) [C:\my_project\node_modules\node-hid\build\HID.vcxproj]
..\src\HID.cc(70): warning C4290: C++ exception specification ignored except to indicate a function is not __declspec(nothrow) [C:\my_project\node_modules\node-hid\build\HID.vcxproj]
..\src\HID.cc(92): error C2061: syntax error : identifier 'NanCallback' [C:\my_project\node_modules\node-hid\build\HID.vcxproj]
..\src\HID.cc(106): error C2143: syntax error : missing ';' before '*' [C:\my_project\node_modules\node-hid\build\HID.vcxproj]
.... (the list goes on)
When I tried VS2008/VS2008 express, I received warnings that stdint.h was missing. I tried several stdint.h's that were contributed by the community, including one in the NodeJS distribution for Windows that was actually named "stdint-msvc2008.h". No matter which stdint.h I put into VS2008's include folder, I would get a huge explosion of angry warnings regarding mismatches etc.
When I tried to build on VS2010, I would get a generic MSBxxxx warning about labels.
When I tried VS2013 I get a lot of "nanthrowerror" messages. I get the same "nan.h" related error messages for various node_modules I try to build.
All of the help files and Windows with NodeJS advice and help threads that I find seem revolved around helping developers solve environment/variable issues, helping them install VS in the correct order, helping them install node-gyp and helping them use the correct --msvs_version=vsxxx tag. As far as I can tell, none of these are my issue. I don't get any warnings about a missing vcbuild.exe or missing msbuild.exe, it is indeed trying to compile using the Visual Studio Express installation on my machine, but I am missing something.
First off, what can I do to help provide more information on my question?
Related threads and references:
https://github.com/nodejs/node-gyp/blob/master/README.md
Cannot install node modules that require compilation on Windows 7 x64/VS2012
(I have more links to share, but it says my reputation is not high enough)

You're using the pre-4.0 syntax of NaN with a 4.0 node release. They just changed everything and it bit me pretty bad. NanThrowError is now Nan::ThrowError, etc...
There is helpful information in here: https://github.com/nodejs/nan/issues/402
And I found the regexes here: https://github.com/nodejs/nan/issues/376#issuecomment-120838432 to be extremely helpful in converting.
You should also read through the docs at https://github.com/nodejs/nan which are incomplete, but still the best thing going right now.

Solution:
Uninstall NodeJS 4.0.x for Windows.
Install NodeJS 0.10.x, 0.11.x, or 0.12.x for Windows.
Being a newbie to NodeJS, I didn't realize that any two given versions of NodeJS are likely incompatible with each other. 0.10.x to 0.11.x apparently involved a major change to the underlying engine, which caused any modules written for 0.10.x to stop working with 0.11.x.
If you found this thread, just know that 99% of your problems with any NodeJS project will involve getting all of your dependencies from around the same date code. Meaning if your NodeJS core is from let's say March 2014, then any modules you install should be from around that say time frame or else you'll probably have problems. Same goes for any other tools like Atom Electron -- always grab a version that has the same release date as your node core.

Related

Electron build for windows shows sqlite3 error. But same build for Ubuntu Works

Packed using: Electron-Packager
Database: sqlite
The app uses Knex as a driver to query to mysqlite.
The module which it says that it cannot find is already present! But then too the error shows up.
I tried to navigate to the resource/app and then use commands like
npm run rebuild
tried installing python, node and then tried but seems like it required some CL.exe file so had to dowload Visual Studio C++ packages too but unfortunately it didn't have that file in my case.
Also tried
npm install sqlite3 --build-from-source
but got error
Can anyone help me with the exact steps to take? I also need help in knowing do i have to take this steps on the package that is already build or before i build it?
The best possible fix i got is the build the system in windows and then deploy it for windows. You need to google at every step where it breaks and then fix it. There are many possibilities and hence i cannot describe it here.

gulp integration in Visual Studio 2017 not working

I'm attempting to get gulp integration into Visual Studio 2017. It's working on the command line. The Task Runner Explorer in VS2017 is telling me Failed to load. See output window.
The Output Window is telling me the following:
Failed to run "<ProjectPath>\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
<ProjectPath>\node_modules\node-sass\lib\binding.js:15
throw new Error(errors.missingBinary());
^
Error: Missing binding <ProjectPath>\node_modules\node-sass\vendor\win32-x64-47\binding.node
Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 5.x
Found bindings for the following environments:
- Windows 64-bit with Node.js 8.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.
I attempt to run npm rebuild node-sass --force, only to be told Error: Can't find Python executable "C:\Python36\python.EXE", you can set the PYTHON env variable., which I confirmed existed.
I'm not sure how much farther I want to go down this rabbit hole. It appears to be a VS issue since everything works as expected on the command line. I'd like to get the gulp integration with VS working correctly.
Point your VS tools to the node installation on your path.
I can see in the error that there a version discrepancy between 5.x and 8.x - with VS likely being the older one (since it ships with pre-packaged and outdated node) and is taking execution precedence with the default setup.
I'm guessing you installed node-sass via your 8.x (external command line) instance but VS is trying to execute your gulp tasks via your VS's internal 5.x. node-sass leverages node-gyp to build a binary via installation scripts, and there will be incompatibilities across versions. In other words, this package, and many others that build binaries, are specifically tailored to the version of node it was installed against. To summarize, everything in node_modules/.bin is built against 8.x but is actually running on 5.x when you do so through Visual Studio.
Fear not, this is easily solved. Check out this answer for some historical context on this long running issue that many face. Basically, you want $(PATH) to be at the top of this list so your OS installation is always used...
Once you do this (just to be safe) - blow away node_modules, reinstall, and happy coding. VS really needs to stop shipping with pinned versions of node...
I ran into this problem on both Visual Studio 2017 and 2019. Apparently my Node install wasn't registered in the PATH variable (and I don't have permission to modify this on my work machine), so I manually added the link to Node at C:\Program Files\nodejs, moved that to the top location and that worked for me.
This drove me nuts until I found one more missing thing. Even if you configured everything as in the other answers you can get the same error, possibly if your user folder is not on the same drive as where Node is installed. Then also add %APPDATA%\npm to the external tools paths so globally installed Node tools will be found too.
So all in all the external tools config in VS should contain these two paths first, in this order:
C:\Program Files\NodeJS (or where you have Node installed).
%APPDATA%\npm
For me without #2 everything was working from the command line everywhere but not in VS. With it added everything now works in VS too.

Electron throwing error %1 is not a valid win32 application with custom node addon

I've written a custom node addon that works perfectly fine when running the 64 bit version of Electron.
I tried setting the architecture to ia32 and everything builds, but I get the not valid win32 application error, no matter what I do.
My environment settings are:
npm_config_disturl=https://atom.io/download/atom-shell
set npm_config_target=1.0.1
set npm_config_arch=ia32
set npm_config_runtime=electron
set HOME="C:\Users\myHome\.electron-gyp"
set VCTargetsPath=C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140
I have been building the addon by calling npm install.
Here's how I set my node to target 32 bit and install all packages in 32bit format. It works for me. You may try.
npm set npm_config_arch ia32
npm clean-install --arch=ia32
The first command set the node environment to 32bit.
The second command re-install all the node packages that are 32bit compatible.
I was trying to compile for windows from mi Mac and I had that problem too, but after some readings I figured out how to proceed, and after all I can say that I got it. Yesterday I spent all day setting up a windows virtual machine in my (other) Linux laptop (I used my linux laptop just because my mac was exhausted in storage...). I was having too a problem with the preloadScript from electron main process in windows, Cant found the script, it was solved too.
Anyway, I think the library node printer from #tojocky is well maintained, in other hand in the electron-builder documentation they say that you should compile in native for natural reasons. Once you will have it, you'll see that it's a cleaner and pragmatic solution ...
This was my entire process, I hope it helps to someone having the same issue:
Get VirtualBox (or Parallels but is not free)
Get iso for W10
Create a VM with this W10 iso, and you should give to this VM some storage (because some dependency that you'll need to compile), I have assigned 60gb to this VM
Once I had that VM running, I just installed in that machine Visual Studio 2017 (with their build-tools included, it's necessary)
And then, I used CMD to make the rest
Install NodeJS (and NPM, but it comes with)
Install node-gyp globally
Install Python 2.7
Clone your project from git (in my case)
npm i (in your project), you should have as npm dependency in your package.json the module electron-builder of course. (here I had some troubles because when node-gyp tried to rebuild printer to generate the binary for windows it was failing, this was because it was imposible to find the python executable, so if you face this problem you should add it like:npm config set python "c:\Python27\python.exe" in my case )
Then try again npm i and Voila!
After all, you should make the build using electron-builder, in my case my npm script command was build --win --x64 but you can use the --ia32 flag as well for 32bits

Installing Sails leads to Link.exe error in windows

I'm trying to install Sails.JS 0.11.0 to my Windows 7 laptop (intel cpu) but receive an error when npm tries to build it. The error is pasted at the end of this message.
I'm using Node 0.10.38 (required for my use of the OracleDB module, so I can't upgrade to version 12 yet).
My laptop has Visual Studio 2013 Express Desktop which is used to compile.
The Sails npm install completes using npm -g list sails, but with errors, so I worry it's not properly installed.
So far, I've reboot my computer, wiped its temp files, and did everything I can think of. Any suggestions? I can't find any compatibility info on the Sails site (maybe I need to install an older version of Sails?).
The link-cvtres.write.[ID].tlog file referenced below seems to exist in that directory (which is built on the fly)... at least, a version of the file with a "1" in place of the "[ID]" is there.
Any help is appreciated.
Error Message (in the red output):
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.CppCommon.targets(607,5): error MSB6003: The specified task executable "link.exe" could not be run. C:\Users\me\AppData\Roaming
\npm\node_modules\sails\node_modules\sails-hook-sockets\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-client\node_modules\ws\build\Release\obj\validation\validation.tlo
g\link-cvtres.write.[ID].tlog [C:\Users\me\AppData\Roaming\npm\node_modules\sails\node_modules\sails-hook-sockets\node_modules\socket.io\node_modules\socket.io-client\node_modules\engine.io-cl
ient\node_modules\ws\build\validation.vcxproj]`

Install bcrypt without Visual Studio

I'm trying to install bcrypt via npm and I'm getting a Failed at the bcrypt#0.7.8 install script. error.
I'm on Windows 8 x64, node ver 0.10.29.
Looking at bcrypt's dependencies tells me I need node-gyp, which apparently needs visual studio 2012 and python. For real? Do I really need to install a full IDE that I'm not going to use for this one node module?
Is it the compiler node-gyp is after, or some other small component from VS I can install that will do the trick?
Would love any suggestions for how to get this working with minimum possible extras.
As previously mentioned, you can install VC++ Express (and the Windows SDK) for free. However, if you are really that bothered by it, you could use a bcrypt API-compatible module that is implemented in pure javascript, however you will see a performance hit.
I should also note that there are many (useful) modules on npm right now that require compilation, so chances are you'll be getting more use out of the compiler (in the future) than you think.

Resources