NPM install Errors: '../build/Release/bson' 'MODULE_NOT_FOUND' js-bson: Failed to load c++ bson extension, node-gyp.js rebuild, ENOENT




 ISSUE:
Node.js modules build errors
NPM install Errors:  '../build/Release/bson' 'MODULE_NOT_FOUND'  js-bson: Failed to load c++ bson extension, node-gyp.js rebuild, ENOENT

CAUSE:
Even  if python path is set in the Windows' environment variable and in the path, node-gyp is not picking the python path . If you type 'python' from any directory it might work. But node-gyp will still through these errors.  It is confusing as in CLI python works if you call python.exe, but node-gyp doesn't find it, so you decide to try on every thing else you can find online.

- If there is a C++ error , node-gyp rely on visual studio's C++ compiler to build. You might need to set Visual C++ path or version in the CLI command. 

- long directory or path name issue in Windows: Windows only can handle 260 charecters in a given path name (oooooooooops. This is not an easy fix for windows as the core OS is built on top of this limitation.) . You have to make it simpler path starting from C: or from tiny path names for your projects! (See one of the errors below.)

FIX:
node-gyp doesn't pick up python path from environment / the path is not defined correctly in environment variables.

set the environment variable PYTHON to your python.exe
set PYTHON=c:\Python27\python.exe" 

------ OR
set the npm configuration value like this,
 npm config set python = c:\Python27\python.exe

----- OR
C:\WINDOWS\system32>npm install YOUR-PACKAGE --python=C:\Python27\python.exe  

----- OR
If you get error on C++ compiler use --msvs_version = 20xx in the CLI command.

C:\WINDOWS\system32>npm install YOUR-PACKAGE --python=C:\Python27\python.exe  
--msvs_version=2013  (put your current version of Visual studio here)

You can also try ,
npm  cache clean  ( this might need you to start Command prompt with Admin permission)
npm install  YOURPACKAGE  --python=c:\python27\python.exe

So, TRY the above options before you try ,
uninstall ndoe, npm, python, node-gyp, 64 bit versions vs 32 bit versions ,
changing  code in the npm packages ,
or opening Ms command window - shell window in Admin mode,
etc. oops that would be a nightmare.




Errors:

Often the error is logged into a file like (node-gyp rebuild 2> builderror.log) - if you open this file under the relevant package's directory - you will see the same pattern of errors like,
gyp ERR! configure error
gyp ERR! stack Error: spawn C:\Python273 ENOENT
(see full errors below)

Some of these following node packages use node-gyp to build code at your system, and they through the below errors. 

bson  (mongodb, mongocore nodemodules - uses this package, any mongo driver mongo / mongoose will produce this error)
ws
Kerbros
node-gyp configure
 
> ws@0.5.0 install \AppData\Roaming\npm\node_modules\strongloop\n
ode_modules\strong-arc\node_modules\strong-mesh-client\node_modules\engine.io\no
de_modules\ws
> (node-gyp rebuild 2> builderror.log) || (exit 0)

 AppData\Roaming\npm\node_modules\strongloop\node_modules\strong-
 "C:\Program Files (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_mo
dules\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.
 
====================
Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' } 
  js-bson: Failed to load c++ bson extension, using pure JS version


=================== (You will see the same below log in the 'builderror.log')
C:\ >node-gyp configure --msvs
_version=2010
gyp info it worked if it ends with ok
gyp info using node-gyp@1.0.3
gyp info using node@0.12.0 | win32 | ia32
gyp ERR! configure error
gyp ERR! stack Error: spawn C:\Python273 ENOENT
gyp ERR! stack     at exports._errnoException (util.js:746:11)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1046
:32)
gyp ERR! stack     at child_process.js:1137:20
gyp ERR! stack     at process._tickCallback (node.js:355:11)
gyp ERR! stack     at Function.Module.runMain (module.js:503:11)
gyp ERR! stack     at startup (node.js:129:16)
gyp ERR! stack     at node.js:814:3
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok


===================
gyp: binding.gyp not found (cwd: C:\ \ \NodeWorkspace\Tutorials\loopbackinter\node_modules\loopback-connector-mongodb\node_modules\mongodb\node_modules\mongodb-core\node_modules\bson) while trying to load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\configure.js:343:16)
gyp ERR! stack     at ChildProcess.emit (events.js:110:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:1067:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "node" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\ \NodeWorkspace\Tutorials\loopbackinter\node_modules\loopback-connector-mongodb\node_modules\mongodb\node_modules\mongodb-core\node_modules\bson
gyp ERR! node -v v0.12.0
gyp ERR! node-gyp -v v1.0.3
gyp ERR! not ok


=================
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(25
3,5): error MSB3491: Could not write lines to file "Release\obj\bson\bson.lastb
uildstate". The specified path, file name, or both are too long. The fully qual
ified file name must be less than 260 characters, and the directory name must b
e less than 248 characters. [C:\Users\xxx\ \loopback-getting-started-intermediate-master\node_modules\loopback-connector-mo
ngodb\node_modules\mongodb\node_modules\mongodb-core\node_modules\bson\node_mod
ules\bson-ext\build\bson.vcxproj]

========================
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xlocale(323): wa
rning C4530: C++ exception handler used, but unwind semantics are not enabled.
Specify /EHsc [C:\Users\loopback-inter
mediate\node_modules\loopback-connector-mongodb\node_modules\mongodb\node_modul
es\mongodb-core\node_modules\kerberos\build\kerberos.vcxproj]
c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xlocale(323): wa
rning C4530: C++ exception handler used, but unwind semantics are not enabled.
Specify /EHsc [C:\Users\loopback-inter
mediate\node_modules\loopback-connector-mongodb\node_modules\mongodb\node_modul
es\mongodb-core\node_modules\kerberos\build\kerberos.vcxproj]

=============
 C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\xlocale(337): wa
rning C4530: C++ exception handler used, but unwind semantics are not enabled.
Specify /EHsc
[C:\Users\ \ \NodeWorkspace\Tutorials\loopbackinter\
node_modules\loopback-connector-mongodb\node_modules\mongodb\node_modules\mongo
db-core\node_modules\bson\node_modules\bson-ext\build\bson.vcxproj]
..\ext\bson.cc(809): warning C4530: C++ exception handler used, but unwind sema
ntics are not enabled. Specify /EHsc [C:\Users  \NodeWorkspace\T
utorials\loopbackinter\node_modules\loopback-connector-mongodb\node_modules\mon
godb\node_modules\mongodb-core\node_modules\bson\node_modules\bson-ext\build\bs
on.vcxproj]

============
c:\users\  \nodeworkspace\tutorials\loopbackinter\node_modules\lo
opback-connector-mongodb\node_modules\mongodb\node_modules\mongodb-core\node_mo
dules\bson\node_modules\bson-ext\node_modules\nan\nan_new.h(209): warning C4244
: 'argument' : conversion from 'int64_t' to 'double', possible loss of data
[C:
\Users\ NodeWorkspace\Tutorials\loopbackinter\node_modules\loop
back-connector-mongodb\node_modules\mongodb\node_modules\mongodb-core\node_modu
les\bson\node_modules\bson-ext\build\bson.vcxproj]

Comments