nodejs / node-gyp

Node.js native addon build tool
MIT License
9.9k stars 1.79k forks source link

node-gyp rebuild fails in VS2015 due to wrong path #842

Closed thomas-darling closed 8 years ago

thomas-darling commented 8 years ago

Package restore in Visual Studio 2015 fails with the following:

> bufferutil@1.2.1 install C:\MyProject\node_modules\bufferutil
> node-gyp rebuild
C:\MyProject\node_modules\bufferutil>node "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild 
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(156,5): Error : module.js:340
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(156,5): Error :     throw err;
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(156,5): Error :           ^
DNU(0,0): Error : Cannot find module 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js'
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(156,5): Error :     at Function.Module._resolveFilename (module.js:338:15)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(156,5): Error :     at Function.Module._load (module.js:280:25)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(156,5): Error :     at Function.Module.runMain (module.js:497:10)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(156,5): Error :     at startup (node.js:119:16)
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\Web\Microsoft.DNX.Publishing.targets(156,5): Error :     at node.js:906:3
npm ERR! bufferutil@1.2.1 install: `node-gyp rebuild`
npm ERR! Exit status 8
npm ERR! 
npm ERR! Failed at the bufferutil@1.2.1 install script.
npm ERR! This is most likely a problem with the bufferutil package,
npm ERR! not with npm itself.

Looks like the file path to node-gyp.js is wrong - I believe it should be:

C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\node-gyp\bin\node-gyp.js

This may be a result of installing the lates Node.js Tools for Visual Studio (I'm not sure this is the cause though) https://www.visualstudio.com/en-us/features/node-js-vs.aspx

bnoordhuis commented 8 years ago

This may be a result of installing the lates Node.js Tools for Visual Studio

Looks like it, going by the install path. I don't think this is a node-gyp bug.

thomas-darling commented 8 years ago

Any idea as to where that path comes from? One of the changes in the new Node.js Tools is that it uses a more recent version of NPM, and one of the side-effects of that is, that installed packages are now organize packages in a more flat folder heirachy than before, as the excessive nesting was causing problems due to the max path length limitation in Windows.

I'm guessing that might be why things have moved around in there, so if the path in the error log is hardcoded in, or constructed by, something, then that something might need to be updated to take into account that the folder structure has changed in this version of Node.js Tools - it's only a guess, but seems like this might be the issue - so yeah, maybe not an issue with node-gyp, but affecting it none the less.

I found this other post mentioning the problem: https://www.linkedin.com/pulse/visual-studio-2015-aspnet-5-project-introduction-la-fontaine?trkSplashRedir=true&forceNoSplash=true

Following that advice, I now get this error - any idea what that might mean? This seems to be related to MSVSVersion.py in node-gyp, so assuming the fix in the above post is actually good advice, this now sounds like it is maybe getting the version wrong or something stupid like that - any idea how to work around that?

> utf-8-validate@1.2.1 install C:\MyProject\node_modules\utf-8-validate
> node-gyp rebuild
C:\MyProject\node_modules\utf-8-validate>node "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild 
Traceback (most recent call last):
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py", line 18, in <module>
    sys.exit(gyp.script_main())
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 534, in script_main
    return main(sys.argv[1:])
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 527, in main
    return gyp_main(args)
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 503, in gyp_main
    options.circular_check)
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\__init__.py", line 98, in Load
    generator.CalculateVariables(default_variables, params)
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\generator\msvs.py", line 1867, in CalculateVariables
    generator_flags.get('msvs_version', 'auto'))
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\MSVSVersion.py", line 402, in SelectVisualStudioVersion
    versions = _DetectVisualStudioVersions(version_map[version], 'e' in version)
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\MSVSVersion.py", line 339, in _DetectVisualStudioVersions
    path = _RegistryGetValue(keys[index], 'InstallDir')
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\MSVSVersion.py", line 177, in _RegistryGetValue
    text = _RegistryQuery(key, value)
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\MSVSVersion.py", line 159, in _RegistryQuery
    text = _RegistryQueryBase('Sysnative', key, value)
  File "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\Extensions\Microsoft\Web Tools\External\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\MSVSVersion.py", line 130, in _RegistryQueryBase
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
  File "C:\Python27\lib\subprocess.py", line 702, in __init__
    errread, errwrite), to_close = self._get_handles(stdin, stdout, stderr)
  File "C:\Python27\lib\subprocess.py", line 823, in _get_handles
    p2cread = _subprocess.GetStdHandle(_subprocess.STD_INPUT_HANDLE)
WindowsError: [Error 6] The handle is invalid
gyp
npm ERR! utf-8-validate@1.2.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the utf-8-validate@1.2.1 install script.
npm ERR! This is most likely a problem with the utf-8-validate package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get their info via:
npm ERR!     npm owner ls utf-8-validate
npm ERR! There is likely additional logging output above.
npm ERR! System Windows_NT 6.1.7601
npm ERR! command "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Web Tools\\External\\\\node\\node" "C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\Extensions\\Microsoft\\Web Tools\\External\\npm\\node_modules\\npm\\bin\\npm-cli.js" "install"
npm ERR! cwd C:\MyProject
npm ERR! node -v v0.10.31
npm ERR! npm -v 1.4.9
npm ERR! code ELIFECYCLE
npm

====npm command completed with exit code 1====
mousetraps commented 8 years ago

Node.js Tools dev here - as mentioned in https://github.com/Microsoft/nodejstools/issues/649#issuecomment-170407226, this isn't an NTVS issue, but rather an issue with the Web Tools component that ships with Visual Studio, which installs a private version of node / npm into this path, which apparently doesn't work with native modules. I'll get in touch with the Web Tools team about this to see if it can be fixed in VS2015 Update 2.

In any case, as @bnoordhuis mentioned, this isn't a node-gyp issue, so feel free to close this issue and we'll continue tracking this in our Node.js Tools repo for now (https://github.com/Microsoft/nodejstools/issues/649)

bnoordhuis commented 8 years ago

I'll close, not a node-gyp issue.

ffroliva commented 7 years ago

I solved the problem by updating my enviroment to node@6.10.3 and npm@3.10.10 The problem happend with node-gym@3.3.1