Some Common Vercel Errors
Published: 2023-05-15 13:26:06

When deploying your server-side on Vercel, you may face some common errors sometime. In this blog, I will provide solutions to help you resolve these following errors effortlessly.


1) **<u>Error</u>**

> Cannot GET/your_route_name

**<u>Solution</u>**

**Step-1:** Remove **"await client.connect ()**" in the **try** block of the **run** function of your **index.js** file

**Step-2:** Go to your **vercel.json** file and change your **dest** value to **index.js** like the one below: 

```
{
   "version": 2,
   "builds": [
       {
           "src": "./index.js",
           "use": "@vercel/node"
       }
   ],
   "routes": [
       {
           "src": "/(.*)",
           "dest": "index.js"
       }
   ]
}
```

**Step-3**: Then, run these command on your terminal

```
vercel
vercel --prod
```

2) **<u>Error</u>**

> This Serverless Function has crashed


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qzxvm1abfwspuq1o5wd1.jpg)

_This error have few possible solutions_

<u>Solution - 1</u>

**Step-1:** Remove **"await client. connect ()"** in the **try** block of the **run** function of your index.js file

**Step-2:** Then, run these command on your terminal

```
vercel
Vercel --prod
```

<u>Solution - 2</u>

**Step-1:** Go to your index.js file, remove **app.use(cors())** and write this code instead:

```
const corsConfig = {
    origin: '',
    credentials: true,
    methods: ['GET', 'POST', 'PUT', 'DELETE']
}
app.use(cors(corsConfig))
app.options("", cors(corsConfig))
```

**Step-2:** Then, go to your **vercel.json** file and copy-paste this code:

```

{
    "version": 2,
    "builds": [
        {
            "src": "./index.js",
            "use": "@vercel/node"
        }
    ],
    "routes": [
        {
            "src": "/(.*)",
            "dest": "/",
            "methods": ["GET", "POST", "PATCH", "DELETE", "OPTIONS"]
        }
    ]
}
```

**Step - 3:** Then, run these command on your terminal

```
vercel
Vercel --prod
```

_If you still see the error change **dest** value to **"dest": "index.js"** and deploy the server again using the **step-3** command.

<u>Solution-3</u>

Check if you have added your environment variables in your Vercel

**Go to Vercel dashboard --> Choose the project --> settings--> Environment Variables** 

_Make sure the enviroment variables you added match with the one in your .env file_

<u>Solution-4</u> 

If any of the above solutions don’t work, then run this command on your terminal 

```
vercel logs your_production_url
```

Vercel will let you know if there is any errors in your index.js file.

3) **Error**

> bad credentials Vercel sign up

**Step-1:** Run this command on your terminal to uninstall Vercel

```
npm uninstall -g vercel
```

**Step-2:** Re-install Vercel globally

```
npm i -g vercel
```

**Step-3:** Now login using the command below:
	

```
vercel login
```

4) **Error** 

> This Serverless function has timed out

Visit this blog to resolve this issue:

https://dev.to/shafia/the-errors-you-may-face-for-not-whitelisting-the-ip-address-0000-in-your-mongodb-network-access-32f8

5) **Error**

> Fix vercel error : A system error occurred: uv_os_gethostname returned ENOSYS (function not implemented)

_If you are using Windows 7, you may face this error_

<u>Solution:</u>

**Step-1:** Go to Users -->your_computer_name folder –>
node_modules->vercel->dist->index.js 

**Step-2:** On the top write,
 

```
const os=require("os")
os.hostname=()=>"localhost"
```


Lastly, if you don’t know how to deploy your server using Vercel CLI, follow this blog

https://medium.com/@shafiarahmanchy13/how-to-deploy-a-node-express-server-using-vercel-cli-f0a464d4e88c

For each error, I have provided step-by-step solutions to help you resolve them effectively. 

By following the steps outlined in this blog, you can troubleshoot and overcome these errors.

Happy deploying!