error in npm install inspite of changing the file

2019-02-15 13:26发布

问题:

using mongodb3.0, node 0.12.0, npm 2.5.1 on windows 7 integrale, I am trying to read and write data into my database, but i have this error in npm intsall!

{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }

js-bson: Failed to load c++ bson extension, using pure JS version
{ [Error: Cannot find module '../build/Release/bson'] code: 'MODULE_NOT_FOUND' }

js-bson: Failed to load c++ bson extension, using pure JS version

i tried to replace

bson = require('../build/Release/bson');

into

bson = require('../browser_build/bson');

but i had errors like this:

 exports.BSON.BSON_BINARY_SUBTYPE_DEFAULT = 0 TypeError: Cannot set property       'BSON_BINARY_SUBTYPE_DEFAULT' of undefined  

i am using monk, anfd i have run npm mongodb, npm monk

回答1:

Problem: Modules like Mongo-DB, Socket.io and other requires node-gyp to compile C/C++ code which Kim also discussed. MSVC++ comes only for 32-bit OS, NOW this is the real problem because if you've install node.js and the other requirments like Python 2.7.3 with the 64-bit versions, then you'll face the problems like I did.

Follow these steps:

  • Uninstall Node.js
  • Uninstall all the Modules including Python
  • Now Install 32-bit versions of all the above uninstalled applications and platforms.
  • Follow all the necessary steps.
  • Now install modules you want to use.

You may see some errors while installing, but don't panic. Try running your application and it will work just fine.

NOTE: This solution is platform specific i.e. for MS Windows.



回答2:

I'm on windows 8.1, but what I did, was first install python 2.7.9 and also visual studio community edition. Both are needed to compile bson. Then I installed: "npm install -g node-gyp", after that I just deleted the node_modules from my project and did "npm install" again. Solved. When I did the install again I could see the message on the console that said bson was compiling.



回答3:

MongoDB depends on a few libraries. At some point you would have done:

npm install mongodb --save

One of these dependencies is node-gyp which is needed to compile bson. Importantly, node-gyp requires Python 2.7 and Microsoft Visual Studio to be installed (see installation section of node-gyp). If you don't have Python 2.7 and Visual Studio, then node-gyp will fail to build which means it can't compile bson (causing the initial error).

Navigate to: node_modules\mongodb\node_modules\mongodb-core\node_modules\bson

You should find the builderror.log file with more information about why node-gyp failed to build. Most likely this will be due to Python 2.7 or Visual Studio not being installed.

Here's what I had to do to fix it:

I had the exact same problem as you with the bson module not found error. I also changed the require line as you did and ended up with the same error (exports.BSON...). I then uninstalled monk and mongodb:

npm uninstall mongodb --save
npm uninstall monk --save

Installed Python 2.7 and Microsoft Visual Studio, then installed mongodb and monk again:

npm install mongodb --save
npm install monk --save

This fixed it.



回答4:

The problem is fixed when i changed the version of node 10.34 and nom 1.4.28