Build never end with MongoDB Atlas Integration

Here is my MONGO_URI:
mongodb+srv://vercel-admin-user:(…)@cluster0.xbldt.mongodb.net/myFirstDatabase?retryWrites=true&w=majority

Here is the db.js:

const mongoose = require('mongoose');

const connectDB = async () => {
    try {
        const conn = await mongoose.connect(process.env.MONGO_URI, {
            useNewUrlParser: true,
            useUnifiedTopology: true,
        });
        console.log(`MongoDB Connected: ${conn.connection.host} DB: ${conn.connection.db.databaseName}`);
    } catch (err) {
        console.error(`Error: ${err.message}`);
        process.exit(1); // Exit process with failure
    }
};

module.exports = connectDB;

My IP Access list is set to 0.0.0.0/0 in Atlas.

Why my deployment’s build step do not complete within the maximum of 45min?

Hi @germainb, welcome to the Vercel Community!

Thanks for sharing the project details. I checked your build logs and the project. It seems like you are running node server.js, which is used to run Node.js on servers like EC2. Because Vercel is a serverless platform this command will not work and lead to failed builds.

I’d encourage you to read the Using Express.js with Vercel and update the application code to work with Vercel. These changes should be relatively smaller. You can also look at the Express example solution that works on Vercel.

I hope this was helpful.

Hi,

I added vercel.json file and now it’s working:

{
  "version": 2,
  "builds": [
   { "src": "server.js","use": "@vercel/node" },
   { "src": "package.json", "use": "@vercel/static-build", "config": {"distDir": "dist"} }
  }
  ],
  "routes": [
   {
    "src": "/(.*)",
    "dest": "/server.js"
   }
  ]
 }

The server is here : https://serveur-react.vercel.app/

Thanks!

3 Likes

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