简体   繁体   中英

Error when running node script , Cannot find module 'mongodb/node_modules/bson'

Trying to populate a mongo db with Employee data with the help of mongoose. When running as: node populate_db.js it throws an error saying

module.js:471
    throw err;
    ^

Error: Cannot find module 'mongodb/node_modules/bson' 

not able to check the database value as the database also seems to be empty.

here is my package.json file :

{
  "name": "hr",
  "version": "1.0.0",
  "description": "first node app server",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/pereiraryan/domains.git"
  },
  "keywords": [
    "domains"
  ],
  "author": "ryan pereira",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/pereiraryan/domains/issues"
  },
  "homepage": "https://github.com/pereiraryan/domains#readme",
  "dependencies": {
    "async": "^2.5.0",
    "mongoose-post-find": "0.0.2",
    "colors": "^1.1.2",
    "debug": "0.7.4",
    "express": "4.2.0",
    "mongoose": "^3.8.11"
  } ,
  "scripts": {
    "populate": "node ./bin/populate_db"
    }
}

You can change your mongoose to version 4.2.9 right in you package json file. Power up your json file in an editor and change the version to 'this'. The type 'npm install' in that directory you have your project folder.

npm install -g node-gyp 
cd /to/your/project-folder
rm -rf node_modules
npm install

try doing this also

do npm install inside node_modules/mongodb.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM