500 Due to require statement failing

I am trying to publish an Express JS API to Vercel (server, not serverless). I was able to follow some tutorials on getting it published. However, when running locally it works great. When pushing to Vercel i am getting a 500 due to the app crashing. When checking the logs, it shows a module is missing. Both mongodb and mongoose are within the package.json.

Does anyone have an idea on why this dependency is not able to be found?
Here is the stack trace from the logs:

Cannot find module ‘…/sdam/server_selection’
Require stack:

  • /var/task/node_modules/mongodb/lib/operations/execute_operation.js
  • /var/task/node_modules/mongodb/lib/admin.js
  • /var/task/node_modules/mongodb/lib/index.js
  • /var/task/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js
  • /var/task/node_modules/mongoose/lib/drivers/node-mongodb-native/index.js
  • /var/task/node_modules/mongoose/lib/index.js
  • /var/task/node_modules/mongoose/index.js

Hi, @osidebrandon! Welcome to the Vercel Community :smile:

What does your package.json look like? Both mongodb and mongoose should be listed in dependencies (not devDependencies). Also, make sure you’re using compatible versions of these packages.

Sharing a related guide in case anyone else wanted to learn how to set up Express.js with Vercel.

Thank you for the response!
Yes, both are in the package.json within the dependencies.
When running vercel dev it works great. But when i try to run in vercel in a preview, it has this error.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.