nodejs / node-gyp

Node.js native addon build tool
MIT License
9.94k stars 1.8k forks source link

node-gyp with Windows 8 and Visual Studio 2012 #168

Closed KevinBurton closed 10 years ago

KevinBurton commented 11 years ago

Is there a way that i can configure or rebuild node-gyp to use VS 2012 and the associated SDK? This is the only tool that I have that uses the two year old VS 2010 so to install this suite, its patches, the SDK that is for this compiler, and the patches for the SDK has become troublesome. Right now I am on Windows 8 with VS 2012 and I cannot install the 7.1 SDK because it says it will not install a file that already exists. All in all this is alot of headache to install all of these tools just for node-gyp. Any ideas?

dtpz commented 11 years ago

In case you're on Windows 8 x64 and you're having this problem:

  1. Uninstall all versions of visual C++ redistributables and previous versions of VS
  2. Install Visual Studio 2012 express http://www.microsoft.com/visualstudio/eng/downloads#d-express-windows-8
  3. Install Windows SDK for Windows 8: http://msdn.microsoft.com/en-us/windows/hardware/hh852363.aspx

This worked for me.

I tried all other tutorials and 'fixes' I found on google previously, and none worked - they all mention other versions of Visual Studio and the SDK for windows 7. The above 3 steps is all you need.

msywensky commented 10 years ago

I was finally able to build with Win 8 x64 and VS 2012 Ultimate by setting the msvs_version=2012 and getting latest of node-sqlserver from github.

JayBeavers commented 10 years ago

Much work has gone into fixing this, awaiting final integration of fixes in https://github.com/joyent/node/issues/6667.

srfrnk commented 10 years ago

Try that - will set it globally: npm config set msvs_version 2012 --global

emilingerslev commented 10 years ago

I have also experienced problems with node-gyp. I've been trying to install leveldown on Windows8 x64 with visual studio 2012. But I don't think the issue is at all with the Visual Studio, but rather at problem with Python. I've been trying 2.7.3, 2.7.6, but without luck. After a lot of work I went into the stack trace that is written for the syntax-error, that a few other people also experienced:

Traceback (most recent call last):
  File "C:\Users\Andreas\.node-gyp\0.8.14\tools\gyp\gyp", line 15, in <module>
    import gyp
  File "C:\Users\Andreas\.node-gyp\0.8.14\tools\gyp\pylib\gyp\__init__.py", line
 8, in <module>
    import gyp.input
  File "C:\Users\Andreas\.node-gyp\0.8.14\tools\gyp\pylib\gyp\input.py", line 18
, in <module>
    import shlex
  File "C:\Python27\lib\shlex.py", line 12, in <module>
    from collections import deque
  File "C:\Python27\lib\collections\__init__.py", line 369
    exec(class_definition, namespace)
SyntaxError: unqualified exec is not allowed in function 'namedtuple' it contain
s a nested function with free variables

This error shows that an issue in collectionsinit.py through shlex.py is blowing up. By removing the import statements directly in these gyp files

gyp/__init__.py
gyp/input.py

I could make a completed node-gyp rebuild:

C:\workspace\node-leveldown-master> node-gyp rebuild "--msvs_version=2012"
gyp info it worked if it ends with ok
gyp info using node-gyp@0.9.3
gyp info using node@0.10.26 | win32 | ia32
gyp info spawn python
gyp info spawn args [ 'C:\\Users\\Ein\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=2012',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\workspace\\node-leveldown-master\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\Ein\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\Ein\\.node-gyp\\0.10.26\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\Ein\\.node-gyp\\0.10.26',
gyp info spawn args   '-Dmodule_root_dir=C:\\workspace\\node-leveldown-master',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\workspace\\node-leveldown-master\\build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
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=Win32' ]
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  env_win.cc
  win_logger.cc
  port_uv.cc
  db_impl.cc
  table_cache.cc
  repair.cc
  version_edit.cc
  log_writer.cc
  write_batch.cc
  filename.cc
  version_set.cc
  memtable.cc
  db_iter.cc
  log_reader.cc
  builder.cc
  dbformat.cc
  comparator.cc
  cache.cc
  logging.cc
  hash.cc
  env.cc
  arena.cc
  status.cc
  crc32c.cc
  bloom.cc
  filter_policy.cc
  options.cc
  coding.cc
leveldb-1.14.0\util\bloom.cc(50): warning C4018: '<' : signed/unsigned mismatch [C:\workspace\node-leveldown-master\dep
s\leveldb\leveldb.vcxproj]
  memenv.cc
  merger.cc
  block.cc
  filter_block.cc
  table.cc
  two_level_iterator.cc
  table_builder.cc
  format.cc
  block_builder.cc
  iterator.cc
leveldb-1.14.0\table\filter_block.cc(100): warning C4018: '<=' : signed/unsigned mismatch [C:\workspace\node-leveldown-
master\deps\leveldb\leveldb.vcxproj]
  leveldb.vcxproj -> C:\workspace\node-leveldown-master\build\Release\\leveldb.lib
  snappy-sinksource.cc
  snappy-stubs-internal.cc
  snappy.cc
  snappy.vcxproj -> C:\workspace\node-leveldown-master\build\Release\\snappy.lib
  leveldown.cc
  batch_async.cc
  database_async.cc
  batch.cc
  database.cc
  iterator_async.cc
  leveldown_async.cc
  iterator.cc
     Creating library C:\workspace\node-leveldown-master\build\Release\leveldown.lib and object C:\workspace\node-level
  down-master\build\Release\leveldown.exp
  Generating code
  Finished generating code
  leveldown.vcxproj -> C:\workspace\node-leveldown-master\build\Release\\leveldown.node
gyp info ok

Going futher, trying to install and build through npm install I hit the same problem again through another path: .

C:\workspace\node-leveldown-master> node-gyp.cmd rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@0.10.0
gyp info using node@0.10.26 | win32 | ia32
gyp info spawn python
gyp info spawn args [ 'C:\\Users\\Ein\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\gyp\\gyp',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-G',
gyp info spawn args   'msvs_version=auto',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\workspace\\node-leveldown-master\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\Ein\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\Ein\\.node-gyp\\0.10.26\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\Ein\\.node-gyp\\0.10.26',
gyp info spawn args   '-Dmodule_root_dir=C:\\workspace\\node-leveldown-master',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\workspace\\node-leveldown-master\\build',
gyp info spawn args   '-Goutput_dir=.' ]
Traceback (most recent call last):
  File "C:\Users\Ein\AppData\Roaming\npm\node_modules\node-gyp\gyp\gyp", line 15, in <module>
    import gyp
  File "C:\Users\Ein\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 8, in <module>
    import gyp.input
  File "C:\Users\Ein\AppData\Roaming\npm\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 15, in <module>
    import multiprocessing
  File "C:\Python27\lib\multiprocessing\__init__.py", line 65, in <module>
    from multiprocessing.util import SUBDEBUG, SUBWARNING
  File "C:\Python27\lib\multiprocessing\util.py", line 38, in <module>
    import threading        # we want threading to install it's
  File "C:\Python27\lib\threading.py", line 13, in <module>
    from collections import deque as _deque
  File "C:\Python27\lib\collections\__init__.py", line 368
    exec(class_definition, namespace)
SyntaxError: unqualified exec is not allowed in function 'namedtuple' it contains a nested function with free variables
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\Users\Ein\AppData\Roaming\npm\node_modules\node-gyp\lib\configure.js:415
:16)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:797:12)
gyp ERR! System Windows_NT 6.2.9200
gyp ERR! command "node" "C:\\Users\\Ein\\AppData\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\workspace\node-leveldown-master
gyp ERR! node -v v0.10.26
gyp ERR! node-gyp -v v0.10.0
gyp ERR! not ok

Again the issue with the SyntaxError in collectionsinit.py, but now through threading.py. It seems that the issue is with python, but as I'm not a python or gyp expert I would really like some input on where to go with this bug.

emilingerslev commented 10 years ago

For the "SyntaxError: unqualified exec is not allowed in function 'namedtuple' it contains a nested function with free variables" here is a solution.

First of I found a test for the ensence of the SyntaxError problem with test.py:

import collections
print('success!')

running it through 3 different version of python makes it all a little clearer:

C:\workspace\nodegyp-test> C:\Python26\python.exe .\test.py
success!
C:\workspace\nodegyp-test> C:\Python27\python.exe .\test.py
Traceback (most recent call last):
  File ".\test.py", line 1, in <module>
    import collections
  File "C:\Python27\lib\collections\__init__.py", line 368
    exec(class_definition, namespace)
SyntaxError: unqualified exec is not allowed in function 'namedtuple' it contains a nested function with free variables
C:\workspace\nodegyp-test> C:\Python33\python.exe .\test.py
success!

The recommendations on running node-gyp with python 2.7.3 clearly doesn't fit Windows 8. Trying to run the a build with python 2.6:

C:\workspace\nodegyp-test> npm install leveldown --python=c:\python26\python.exe --msvs_version=2012

npm http GET https://registry.npmjs.org/leveldown
npm http 304 https://registry.npmjs.org/leveldown
npm http GET https://registry.npmjs.org/bindings
npm http GET https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/nan
npm http 304 https://registry.npmjs.org/bindings

> leveldown@0.10.2 install C:\workspace\nodegyp-test\node_modules\leveldown
> node-gyp rebuild

C:\workspace\nodegyp-test\node_modules\leveldown>node "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\
..\..\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.
  env_win.cc
  win_logger.cc
  port_uv.cc
  db_impl.cc
  table_cache.cc
  repair.cc
  version_edit.cc
  log_writer.cc
  write_batch.cc
  filename.cc
  version_set.cc
  memtable.cc
  db_iter.cc
  log_reader.cc
  builder.cc
  dbformat.cc
  comparator.cc
  cache.cc
  logging.cc
  hash.cc
  env.cc
  arena.cc
  status.cc
  crc32c.cc
  bloom.cc
  filter_policy.cc
  options.cc
  coding.cc
leveldb-1.14.0\util\bloom.cc(50): warning C4018: '<' : signed/unsigned mismatch [C:\workspace\nodegyp-test\node_modules
\leveldown\deps\leveldb\leveldb.vcxproj]
  memenv.cc
  merger.cc
  block.cc
  filter_block.cc
  table.cc
  two_level_iterator.cc
  table_builder.cc
  format.cc
  block_builder.cc
  iterator.cc
leveldb-1.14.0\table\filter_block.cc(100): warning C4018: '<=' : signed/unsigned mismatch [C:\workspace\nodegyp-test\no
de_modules\leveldown\deps\leveldb\leveldb.vcxproj]
  leveldb.vcxproj -> C:\workspace\nodegyp-test\node_modules\leveldown\build\Release\\leveldb.lib
  snappy-sinksource.cc
  snappy-stubs-internal.cc
  snappy.cc
  snappy.vcxproj -> C:\workspace\nodegyp-test\node_modules\leveldown\build\Release\\snappy.lib
  leveldown.cc
  batch_async.cc
  database_async.cc
  batch.cc
  database.cc
  iterator_async.cc
  leveldown_async.cc
  iterator.cc
     Creating library C:\workspace\nodegyp-test\node_modules\leveldown\build\Release\leveldown.lib and object C:\worksp
  ace\nodegyp-test\node_modules\leveldown\build\Release\leveldown.exp
  Generating code
  Finished generating code
  leveldown.vcxproj -> C:\workspace\nodegyp-test\node_modules\leveldown\build\Release\\leveldown.node
leveldown@0.10.2 node_modules\leveldown
├── bindings@1.1.1
└── nan@0.6.0

Hope this helps somebody :)

erquhart commented 10 years ago

@einoodle I just trashed an entire day on this issue. Thanks to your post I was able to end it on a good note. Not sure if it was using 2.6 or simply defining the path to the Python executable inline with the command, but it worked. Cheers!

jellydonut commented 9 years ago

this is what worked for me:

npm install zombie --python=C:\tools\python27\python.exe --msvs_version=2013

I am on: Windows 8 visual studio 2013 (Full version)

panuhorsmalahti commented 9 years ago

node-gyp was broken for me when I removed VS2012 (I had VS2013) installed. --msvs_version=2013 fixed the issue, but a proper fix was setting the GYP_MSVS_VERSION=2013 environment variable.

benjaminmbrown commented 9 years ago

I can confirm @jellydonut's solution works:

npm install gulp-sass --python=C:\tools\python27\python.exe --msvs_version=2013

Works. My setup is also: Windows 8 VS 2013

dalanmao commented 9 years ago

I have the same issue, but I resolve this step by step: download the module source code cd the module dir node-gyp configure use the vs2012 to open the vs project and updating the vs project file in the build directory node-gyp build that works ,but not the idea way , use option --msvs_version=2012 not work for me.

catamphetamine commented 9 years ago

I have both Visual Studio Express 2013 and Visual Studio Community 2015 installed.

I was getting

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 build tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...". [G:\work\cinema\node_modules\engine.io\node_modules\bufferutil\build\bufferutil.vcxproj]

The reason was that the latest Node.js for Windows downloaded from https://nodejs.org contains an old npm v2 (and old node-gyp inside that npm v2).

I had to update Node.js'es internal npm (which also updated node-gyp):

(open console as an administrator)
cd "C:\Program Files\nodejs"
npm install npm@latest

npm config set msvs_version 2013

Now it works (seems that it's using VS 2013 for the time being)

merlynee commented 8 years ago

I've been stuck here for a whole day,downloaded and instaled erverything.It doesn't seem to work. however,I run 'npm update',and god finally smiled at me.oh.and deleted everything in folder npm-cashe

merlynee commented 8 years ago

crap,it worked for one minute

msholly commented 7 years ago

I had a similar issue, and the NPM command for windows-build-tools (from Option 1 in the docs) didn't work for me.

I had to get the installer for Visual Studio 2015, and install the C++ tools manually.

Option 2: Install Visual Studio 2015 (or modify an existing installation) and select Common Tools for Visual C++ during setup. This also works with the free Community and Express for Desktop editions.

Hope this helps anyone stumbling onto this problem.