I use mongodb in my project and it tells that can't find bson

I use express in my api project and when i upload it to vercel, i received an error that can’t find module “bson”

Cannot find module ‘bson’
Require stack:

  • /var/task/node_modules/mongodb/lib/bson.js
  • /var/task/node_modules/mongodb/lib/admin.js
  • /var/task/node_modules/mongodb/lib/index.js
  • /var/task/db.js
  • /var/task/server.js
  • /var/task/___now_launcher.js
  • /var/runtime/index.mjs
    Did you forget to add it to “dependencies” in package.json?

If you’re having trouble deploying an Express app, this guide can help.

You can also ask v0 for suggestions tailored to your own project setup.

Hi, @bil-fis! Welcome :wave:

We wrote this Express community post recently, hopefully it helps!

Hi @bil-fis, welcome to the Vercel Community!

Can you confirm if you have the bson - npm package installed and mentioned in the package.json file?

1 Like

I’m sure that i add bson package to package.json

Hi @bil-fis, thanks for confirming. If you need more help, please share your public repo or a minimal reproducible example. That will let us all work together from the same code to figure out what’s going wrong.

Here is the repo https://gitee.com/bil-fis/shiroko-webapi

Hi @bil-fis, thanks for sharing your repository. The project structure doesn’t look correct to me for hosting on Vercel.

I recommend following this post about Express applications on Vercel.

1 Like