Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wethinkagile opened this issue Feb 26, 2015 · 38 comments
Closed

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

wethinkagile opened this issue Feb 26, 2015 · 38 comments

Comments

@wethinkagile
Copy link

I have this error since starting to develop with Mongoose 1,5 years ago.

The error never vanished completely, it comes back after each and every npm update

This error has been a friend and annoyance alongside the road developing with MEANB.

Are there any plans to finally get rid of this error or will it continue to annoy the developer community until the end of all time :)?

@wethinkagile
Copy link
Author

Works:

npm install node-gyp -g
npm cache clean
rm -rf node_modules
npm install

Maybe this should go into the official installation docs?

tl;dr

npm install node-gyp -g && npm cache clean && rm -rf node_modules && npm install

@yaroshevych
Copy link

Can anyone elaborate on this? I have this issue on both Mac and Linux instances. Thanks.

P.S.
I had to set specific version of mongodb in my package json:

"mongodb": "1.4.9"

@RationalGeek
Copy link

This also bit me today in deploying a mongoose app to Heroku. It seems Heroku was installing the 4.X mongoose while I still had 3.X locally. Heroku was getting this error on startup and I wasn't. Once I did 'npm update' to mongoose 4.X it started happening locally as well. I backed out to 3.X locally and on Heroku and now things are working again.

@transitive-bullshit
Copy link

I ran into the exact same issue as RationalGeek on a 100% fresh Heroku app. +1 for a better fix than rolling back mongoose

@vkarpov15
Copy link
Collaborator

What's the exact error message, with stack trace preferably?

@wethinkagile
Copy link
Author

Thanks for looking into this, Valeri.

Steps to reproduce

1.) "rm -rf node_modules" inside main dir of our own project
2.) "npm cache clean"
3.) "npm install" against this packages.json: https://gist.github.com/nottinhill/5a25afb3e3700b79ba1e
4.) Error is thrown. (see below Gist)

Stack Trace and Error message

https://gist.github.com/nottinhill/9851d558092f9d0149e3

Workaround

1.) "npm install -g node-gyp"
2.) cd into "mongoose/**/mongodb-core" dir and pull in bson like this: https://gist.github.com/nottinhill/6ac075b606dea054c053

@nikola-kanacki
Copy link

On Linux:

sudo apt-get update
sudo apt-get install build-essential

On OSX:

xcode-select --install

..then:

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

Works like a charm.

@BradZzz
Copy link

BradZzz commented Apr 8, 2015

Had to npm install inside node_modules/mongodb.

Thanks for the help!

@gbansal7
Copy link

@nottinhill Thanks for your help.

Its working fine now. not giving me Error .

Thanks
Gaurav

@gbansal7
Copy link

@vkarpov15 It's giving me error again. Please Reopen this issue.

Thank you
Gaurav

@vkarpov15
Copy link
Collaborator

What version are you using @gbansal7?

@e00dan
Copy link

e00dan commented Sep 29, 2015

It hit me today.

@vkarpov15
Copy link
Collaborator

@kuzirashi which version of mongoose?

@e00dan
Copy link

e00dan commented Sep 30, 2015

3.8.0, I fixed it with @BradZzz suggestion to:

Had to npm install inside node_modules/mongodb.

@vkarpov15
Copy link
Collaborator

That can help. You might also want to try upgrading to a more recent version :)

@e00dan
Copy link

e00dan commented Sep 30, 2015

I'm afraid I'll break my project. I'm happy with 3.8 working. :)

@vkarpov15
Copy link
Collaborator

If it works, that's fine. Future bug fixes are gonna require upgrading to higher versions of 3.8.x though :)

@adrianw
Copy link

adrianw commented Nov 19, 2015

I still have a problem with this on windows, using and npm3.
I'm on the latest version of mongoose (4.2.6)
Only way round I've found so is to npm install in the mongoose folder and then npm install in mongoose/node_modules/mongodb folder

@vkarpov15
Copy link
Collaborator

@adrianw can you double check your version of mongoose and show me the output you get when you run it? It shouldn't be possible for you to get that error with 4.2.6, considering the fact that this particular require statement isn't in 4.2.6.

@adrianw
Copy link

adrianw commented Nov 20, 2015

@vkarpov15 I was definitely using 4.2.6, I did some more digging last after your reply and discovered it was actually triggered by using the extension/plugin 'mongoose-3x-types' which I've now removed from my project and everything is just perfect again. So if anyone else is still having problems it's worth checking plugins

@Splaktar
Copy link

Saw this with v3.9.7, but rolling back to v3.8.12 seemed to work for now. Using latest NPM and node 4.2.4.

@vkarpov15
Copy link
Collaborator

Don't use 3.9.7. It's deprecated in npm for a reason: it was an unstable dev release from back when mongoose used to use linux kernel version numbering rather than semver. Use 3.8.x or 4.x.

@dhirender-tyagi
Copy link

npm install mongoose@3.8.12

@vkarpov15
Copy link
Collaborator

@dhirender-tyagi what does that comment refer to?

@papajo
Copy link

papajo commented Mar 24, 2016

Thanks @nottinhill, @nikola-kanacki - that resolved my issue (Error: Cannot find module './db.json'
at Function.Module._resolveFilename (module.js:336:15)
at Function.Module._load (module.js:278:25)
at Module.require (module.js:365:17)
at require (module.js:384:17) )

I did this:
npm install -g node-gyp
cd /to/your/project-folder
rm -rf node_modules
npm install

@niftylettuce
Copy link
Contributor

This is still a bug in like every damn version of this package, you can't use it with Node 6.x, you can't use any version prior to 4.x without it breaking and showing this error, what is going on here? Why is there not documented Readme notes?

@niftylettuce
Copy link
Contributor

λ ~/Public/MyProject/ staging* node-gyp rebuild                                                                                                                         ∞
gyp info it worked if it ends with ok
gyp info using node-gyp@3.4.0
gyp info using node@5.10.1 | darwin | x64
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp WARN download NVM_NODEJS_ORG_MIRROR is deprecated and will be removed in node-gyp v4, please use NODEJS_ORG_MIRROR
gyp info spawn /usr/bin/python
gyp info spawn args [ '/Users/nexus/.nvm/versions/node/v5.10.1/lib/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/nexus/Public/MyProject/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/nexus/.nvm/versions/node/v5.10.1/lib/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/nexus/.node-gyp/5.10.1/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/nexus/.node-gyp/5.10.1',
gyp info spawn args   '-Dnode_gyp_dir=/Users/nexus/.nvm/versions/node/v5.10.1/lib/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=node.lib',
gyp info spawn args   '-Dmodule_root_dir=/Users/nexus/Public/MyProject',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp: binding.gyp not found (cwd: /Users/nexus/Public/MyProject) 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 (/Users/nexus/.nvm/versions/node/v5.10.1/lib/node_modules/node-gyp/lib/configure.js:305:16)
gyp ERR! stack     at emitTwo (events.js:100:13)
gyp ERR! stack     at ChildProcess.emit (events.js:185:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:204:12)
gyp ERR! System Darwin 15.5.0
gyp ERR! command "/Users/nexus/.nvm/versions/node/v5.10.1/bin/node" "/Users/nexus/.nvm/versions/node/v5.10.1/bin/node-gyp" "rebuild"
gyp ERR! cwd /Users/nexus/Public/MyProject
gyp ERR! node -v v5.10.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok

@deegahoward
Copy link

Hi guys, just a heads up as I was having all of these issues and nothing seemed to work. I'm sure you all probably read up on the docs but I didn't and missed out the part where you shouldn't include node_modules in your git push to the heroku app.

This doc saved me

https://devcenter.heroku.com/articles/troubleshooting-node-deploys

@askdesigners
Copy link

Well that's fairly obvious. :) Even then though, this issue is ultra annoying. I don't see how a package like mongoose, which is used by thousands upon thousands of devs and projects, and backed by Automattic, can't get this shit sorted out. If there are strict requirements for versions, then PUT IT IN THE SHITTY DOCUMENTATION ON THE VERY FIRST PAGE.

Google searching this issue finds about 5 pages of results of people asking the same damned question! And there is no definitive answer!!!

@niftylettuce
Copy link
Contributor

Upgrading to the latest version of Mongoose and MongoDB worked for me. Though it did take some time to go through all the Mongoose changes in 4.x compared to 3.x!

@askdesigners
Copy link

Are there a lot of breaking changes? The shitty thing is that my mongoose dependency is baked into Keystone js, so I can't easily bump that version.

@molekilla
Copy link

I have this issue with node 6.5.x , mongoose 4.4.x running Ubuntu 16, by switching to node 4.x it works. Question to you guys, now that node 6 will be the new LTS will it work? This seems a huge blocker if not fixed

@vkarpov15
Copy link
Collaborator

@molekilla have you tried rm -rf node_modules && npm install ? And yes, mongoose works in node v6 just fine.

@parth0595
Copy link

Hi.
Change to mongoose 4.2.9 in your package.json. it works for me.

@willypelz
Copy link

i actually fix it with @BradZzz 's comment

@kalburgimanjunath
Copy link

I am getting below issue,
0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli 'D:\Users\e849278\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js',
1 verbose cli 'start' ]
2 info using npm@5.5.1
3 info using node@v8.9.3
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle passport-social@0.0.1prestart: passport-social@0.0.1
6 info lifecycle passport-social@0.0.1
start: passport-social@0.0.1
7 verbose lifecycle passport-social@0.0.1start: unsafe-perm in lifecycle true
8 verbose lifecycle passport-social@0.0.1
start: PATH: D:\Users\e849278\AppData\Roaming\npm\node_modules\npm\bin\node-gyp-bin;d:\nodejs\passport-social\node_modules.bin;C:\Program Files (x86)\Google\Chrome\Application;C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\IBM\RationalSDLC\common;C:\windows\system32;C:\windows;C:\windows\System32\Wbem;C:\windows\System32\WindowsPowerShell\v1.0;C:\Program Files (x86)\IBM\RationalSDLC\ClearCase\bin;D:\Users\e849278.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm;C:\Program Files\TortoiseSVN\bin;C:\Program Files\Common Files\ThinPrint;C:\Program Files (x86)\Git\cmd;C:\Program Files (x86)\GitExtensions;C:\Program Files\1E\NomadBranch;C:\Program Files\nodejs;C:\Ruby24-x64\bin;D:\Users\e849278.dnx\runtimes\dnx-clr-win-x86.1.0.0-rc1-update1\bin;D:\Users\e849278.dnx\bin;C:\Git\cmd;D:\Users\e849278\AppData\Roaming\npm;C:\Program Files\CMake\bin;C:\Program Files\McAfee\DLP\Agent
9 verbose lifecycle passport-social@0.0.1start: CWD: d:\nodejs\passport-social
10 silly lifecycle passport-social@0.0.1
start: Args: [ '/d /s /c', 'node ./bin/www' ]
11 silly lifecycle passport-social@0.0.1start: Returned: code: 1 signal: null
12 info lifecycle passport-social@0.0.1
start: Failed to exec start script
13 verbose stack Error: passport-social@0.0.1 start: node ./bin/www
13 verbose stack Exit status 1
13 verbose stack at EventEmitter. (D:\Users\e849278\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\index.js:280:16)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at EventEmitter.emit (events.js:214:7)
13 verbose stack at ChildProcess. (D:\Users\e849278\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack at emitTwo (events.js:126:13)
13 verbose stack at ChildProcess.emit (events.js:214:7)
13 verbose stack at maybeClose (internal/child_process.js:925:16)
13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:209:5)
14 verbose pkgid passport-social@0.0.1
15 verbose cwd d:\nodejs\passport-social
16 verbose Windows_NT 6.1.7601
17 verbose argv "C:\Program Files\nodejs\node.exe" "D:\Users\e849278\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "start"
18 verbose node v8.9.3
19 verbose npm v5.5.1
20 error code ELIFECYCLE
21 error errno 1
22 error passport-social@0.0.1 start: node ./bin/www
22 error Exit status 1
23 error Failed at the passport-social@0.0.1 start script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 1, true ]

@vkarpov15
Copy link
Collaborator

@kalburgimanjunath I don't see mongoose anywhere in your stack trace, why is this related to mongoose?

@yugalk14
Copy link

@parth0595 it worked for me as well. Thanks

@Automattic Automattic locked as resolved and limited conversation to collaborators Apr 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests