0

I'm deploying a Node.js backend using Mongoose, and I'm getting the following error during build on Vercel:

Error: Cannot find module './bulkWriteResult'
Require stack:
- /vercel/path0/backend/node_modules/mongoose/lib/drivers/node-mongodb-native/index.js
...

It seems like Mongoose is trying to load a file bulkWriteResult.js internally, but it doesn't exist in the node_modules directory. The error is causing the deployment to fail with:

Error: Command "node server.js" exited with 1

Tried:

  • Deleting and reinstalling node_modules and package-lock.json

  • Ensuring Mongoose is properly installed

  • Checking Node.js version compatibility (v22.17.1 on Vercel)

package.json file:

{
    "name": "backend",
    "version": "1.0.0",
    "main": "server.js",
    "type": "module",
    "scripts": {
        "test": "echo \\"Error: no test specified\\" && exit 1",
        "start": "node server.js",
        "server": "nodemon server.js"
    },
    "author": "",
    "license": "ISC",
    "dependencies": {
        "bcrypt": "^5.1.1",
        "cloudinary": "^2.5.1",
        "cors": "^2.8.5",
        "dotenv": "^16.4.7",
        "express": "^4.21.2",
        "jsonwebtoken": "^9.0.2",
        "mongodb": "^6.18.0",
        "mongoose": "8.17.0",
        "multer": "^1.4.5-lts.1",
        "nodemon": "^3.1.9",
        "razorpay": "^2.9.5",
        "serverless-http": "^3.2.0",
        "validator": "^13.12.0"
    },
    "description": ""
}

How can I fix this missing bulkWriteResult issue? Is it a version-specific bug in Mongoose? Do I need to downgrade or pin a specific version?

4
  • Can you share the full require stack from the error? Commented Aug 1 at 12:57
  • Require stack: - /vercel/path0/backend/node_modules/mongoose/lib/drivers/node-mongodb-native/index.js - /vercel/path0/backend/node_modules/mongoose/lib/index.js - /vercel/path0/backend/node_modules/mongoose/index.js Commented Aug 1 at 13:40
  • 2
    I see no possible reason for it to not exist, it exists in 8.17.0. Please, provide server.js. It's unclear why "type": "module" is there. If you don't use native esm, remove it, this can affect module resolution Commented Aug 1 at 13:45
  • Facing the same problem on heroku, did you find a solution? I've faced this previously on Render and the following solved the issue for me so you could try it too: community.render.com/t/… But let everyone here know if you find something else that works as well. I am shifting from Render to heroku due to payment issues. Commented Aug 5 at 7:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.