WiseLibs / better-sqlite3

The fastest and simplest library for SQLite3 in Node.js.
MIT License
5.55k stars 393 forks source link

The process I had to go through to get this installed on Windows 10 #73

Closed photonstorm closed 6 years ago

photonstorm commented 7 years ago

After a lot of trial and error I finally managed to get this package installed on Windows 10. I'm logging some of my journey here to aid anyone else searching for similar issues in the future.

My set-up: Windows 10, Python 2.7 (32-bit) and node v6.4.0 (32-bit). I had Python 3 installed as well so modified my environment vars so that issuing the command python from the command line took me into the 2.7 release. If it doesn't do that, node-gyp won't work.

When trying to install better-sqlite3 it errored as node-gyp tries to compile the win_delay_load_hook.cc module:

> integer@1.0.1 install d:\wamp\www\phaser3-docs\node_modules\integer
> node tools/install

d:\wamp\www\phaser3-docs\node_modules\integer>if not defined npm_config_node_gyp (node "c:\Program Files\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "" rebuild ) 
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  win_delay_load_hook.cc
  integer.cpp
..\src\integer.cpp(392): error C2144: syntax error : 'double' should be preceded by ';' [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(392): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(393): error C2144: syntax error : 'double' should be preceded by ';' [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(393): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(393): error C2086: 'int Integer::constexpr' : redefinition [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
          ..\src\integer.cpp(392) : see declaration of 'Integer::constexpr'
..\src\integer.cpp(394): error C2146: syntax error : missing ';' before identifier 'uint64_t' [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(394): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(394): error C2086: 'int Integer::constexpr' : redefinition [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
          ..\src\integer.cpp(392) : see declaration of 'Integer::constexpr'
..\src\integer.cpp(395): error C2146: syntax error : missing ';' before identifier 'uint64_t' [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(395): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(395): error C2086: 'int Integer::constexpr' : redefinition [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
          ..\src\integer.cpp(392) : see declaration of 'Integer::constexpr'
..\src\integer.cpp(127): error C2597: illegal reference to non-static member 'Integer::U32_in_U64' [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(127): error C3867: 'Integer::U32_in_U64': function call missing argument list; use '&Integer::U32_in_U64' to create a pointer to member [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
..\src\integer.cpp(127): error C2568: '&' : unable to resolve function overload [d:\wamp\www\phaser3-docs\node_modules\integer\build\integer.vcxproj]
          unable to recover from previous error(s); stopping compilation

I checked and it was using the 2013 version of the msvs tools, so I set msvs_version to 2015.

This got me a little bit further.

Now I got the Cl.exe not found error. The easiest way to fix this was to actually run Visual Studio 2015 and try to create a C++ project (not C#!). C++ build support isn't installed by default, so doing this forced VS to download everything it needed (all 3GB of it).

Trying to install better-sqlite3 now gives a warning in win_delay_load_hook.cc: ..\src\integer.cpp(370): warning C4804: '-': unsafe use of type 'bool' in operation (plus some warnings about uint64_t conversion) - but it did get past that and created the library, generated the code and then errored on lzz-gyp complaining about 'Make' not being installed (which clearly it isn't on Windows).

I had added LZZ_COMPAT=1 to my environment variables earlier on while trying to get it running - but this actually caused the above error. So as per the advice in the lzz-gyp repo I removed those vars and indeed it now gets past that section.

Now it dies on node-gyp rebuild saying it "Cannot find module node-gyp\bin\node-gyp.js", which is weird as it's globally installed on my system! So, I ran npm install node-gyp locally in my project folder and that completed, after which I finally got to install better-sqlite3 and it got to the very end with no red text errors. There were lots of yellow build warnings, but I'll take those happily.

To summarize for Windows 10 users:

1) Ensure you've got Python 2.7, not 3, and that you can run it from the command prompt 2) Ensure Python and Node are both 32-bit, or both 64-bit, but not a mixture of the two 3) Don't add LZZ_COMPAT=1 to your environment vars 4) Install node-gyp locally, it doesn't seem to pick-up a globally installed version 5) Install Visual Studio 2015 with C++ support (or if already installed, try and create a C++ project), this will fix dependency issues with Cl.exe, paths, etc - this is the only thing that worked for me, installing the windows-build-tools package didn't resolve pathing issues. 6) Use npm config set msvs_version 2015 once the above is all done.

On a plain vanilla install of Windows you may not need to do any of this, but as I had multiple versions of Visual Studio already installed, multiple versions of Python, etc, it was a real hornets nest to unpick and configure.

Good luck!

JoshuaWise commented 7 years ago

Thanks for documenting your process. It looks like all of this is covered in the troubleshooting guide, except for:

Install node-gyp locally, it doesn't seem to pick-up a globally installed version

I'll have to investigate why that's happening.

ghassanpl commented 7 years ago

I had a similar problem, and did everything in the troubleshooting guide but the install was still failing with `Error: Cannot find module '\node_modules\node-gyp\bin\node-gyp.js' so I installed node-gyp locally and better-sqlite3 installed fine.

nullivex commented 6 years ago

I had the same issue and here is my process for fixing it: https://github.com/JoshuaWise/better-sqlite3/issues/79#issuecomment-359542121