[solved] Error: Cannot find module "mongodb"

Hi
After updating to 1.6.1.1, my app won’t run, crashing with message 'Error: Cannot find module “mongodb” '.
Tried to run meteor npm install, even took away the entire node_modules folder and built it again.
Tried to run meteor npm update.
Tried to run meteor npm install mongodb.
Tried to downgrade back to version 1.6.0.1.
Still can’t find mongodb.

Important - mongodb is there, all collections are there - I can access it through the terminal with “meteor mongo”.

Any help before my boss kills me?

If it helps - The data in the db can be erased if there is no other way.

(running on ubuntu 16.04)

Thanks

Edit:

New development:
I started a whole new project, and the problem exists there olso… It means that the problem is not in the project but in “global” meteor itself, right?
I tried to find solution for this, and I keep getting “uninstall and install meteor globally”. I’m afraid it would make a mess in my existing project. Is it safe? Is there any other solution?

Do you have mongodb listed in your project’s .meteor/packages file?

Erm, isn’t the included Meteor package for MongoDB called simply mongo?

I mean, I’m doing

import { Mongo } from 'meteor/mongo';

and that works just fine.

2 Likes

Correct - just checking everyone’s paying attention :wink:

You know what? It’s strange.

In .meteor/packages there’s this:
mongo@1.4.2 # The database Meteor supports right now

but in package.json, under dependencies, there’s this:
“mongodb”: “^3.1.0-beta4”,

while in the version before the update (when everything worked) mongodb doesn’t appear in package.json at all (I don’t have the last version of .meteor/packages because I keep only my code on rtc).

Should I try to remove mongodb line from package.json and install mongo@1.4.2, as it appears in .meteor/packages, or should I do the opposite and try to update .meteor/packages to version 3.1.0-beta4?

What have I done wrong??

This:

Lead to this:

You need the version in .meteor/packages. But even then it shouldn’t be an issue as the mongodb is called from meteor package. Anyway remove it from the package.json and run meteor update and meteor npm install.
I would also check that you are not trying to import pure mongodb somewhere (as the error might suggest).
You have to import as @rhywden said.

2 Likes

Yes, as @storyteller says, use the Meteor version. This means that there should be no instance of Mongo in package.json anywhere because Meteor installs that automatically upon startup (as long as it’s in packages, of course).

Basically, you have to packaging systems here: The Meteor one (packages listed in packages) and the npm one (package.json). You should try to avoid duplicates.

2 Likes

Did it:

  1. removed mongo from package.json
  2. meteor update --release 1.6.1.1 => “This project is already at Meteor 1.6.1.1.”
  3. meteor npm install => “removed 7 packages in 4.374s”

Still "Error: Cannot find module ‘mongodb’ "

I think it took me back to the original state, where the problem first occured…

Should I try to manually install mongo with the packages version, and then remove it again from package.json?

Of course, in my code I import mongo the right way only, as @rhywden mentioned. Also, the error seems to appear at the initializing of meteor itself and not in the code, because the location is in …/.meteor/local/build/programs/server/boot.js:288:32, which looks to me like something that happens before meteor gets to the coded files (I don’t really know, just from the file name & location).

Can you please post the full error message?

Have you tried

meteor add mongo

Make sure you’ve removed the mongodb entry from package.json.

Meteor always adds mongo, so I’m not sure why it would have disappeared in the first place though.

New development:
I started a whole new project, and the problem exists there olso… It means that the problem is not in the project but in “global” meteor itself, right?
I tried to find solution for this, and I keep getting “uninstall and install meteor globally”. I’m afraid it would make a mess in my existing project. Is it safe? Is there any other solution?

Please post the whole error message / stack trace.

/home/appName/.meteor/local/build/programs/server/boot.js:467
}).run();
^
Error: Cannot find module ‘mongodb’
at Function.Module._resolveFilename (module.js:536:15)
at Function.resolve (internal/module.js:18:19)
at Object.require (/home/appName/.meteor/local/build/programs/server/boot.js:287:32)
at packages/npm-mongo.js:19:24
at packages/npm-mongo.js:24:4
at packages/npm-mongo.js:37:3
at infos.forEach.info (/home/appName/.meteor/local/build/programs/server/boot.js:414:13)
at Array.forEach ()
at /home/appName/.meteor/local/build/programs/server/boot.js:413:9
at /home/appName/.meteor/local/build/programs/server/boot.js:463:5
=> Exited with code: 1

@rhywden @storyteller

thanks!

Uninstalling and installing meteor globally is safe as all you meteor config for your app (and local db) resides in your project so it can’t mess it up any more than it already is. I would give it a try as it is fairly quick solution if there is something messed up with your local install.

1 Like

In the end, I uninstalled and re-installed meteor globally, and everything got back to normal…

Thank you all!

3 Likes