<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Farhan Hasan Nilok</title>
    <description>The latest articles on DEV Community by Farhan Hasan Nilok (@nilok).</description>
    <link>https://dev.to/nilok</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1236848%2F1a3ae992-6069-4917-a278-8f83d543270a.jpg</url>
      <title>DEV Community: Farhan Hasan Nilok</title>
      <link>https://dev.to/nilok</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/nilok"/>
    <language>en</language>
    <item>
      <title>How to Solve Vercel Server Less function Crushed 500 Error for Express Server.</title>
      <dc:creator>Farhan Hasan Nilok</dc:creator>
      <pubDate>Tue, 19 Dec 2023 17:29:50 +0000</pubDate>
      <link>https://dev.to/nilok/how-to-solve-vercel-server-less-function-crushed-error-for-express-server-445a</link>
      <guid>https://dev.to/nilok/how-to-solve-vercel-server-less-function-crushed-error-for-express-server-445a</guid>
      <description>&lt;h2&gt;
  
  
  &lt;strong&gt;Introduction&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Working with serverless functions on platforms like Vercel can be a seamless experience, but occasionally, challenges may arise. Recently, I encountered a serverless function crash on Vercel, and I'm here to share how I resolved it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexfzsdgbhosvgmxsnfid.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fexfzsdgbhosvgmxsnfid.png" alt="Vercel Error Image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;The Problem&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;The issue manifested as a 500 Internal Server Error, and the logs pointed towards a missing module: Cannot find module 'express'. This error message was puzzling as express was part of the project dependencies. The Error code looks like this,&lt;/p&gt;

&lt;p&gt;`Cannot find module 'express'&lt;br&gt;
Require stack:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;/var/task/index.js&lt;/li&gt;
&lt;li&gt;/var/task/___now_launcher.js&lt;/li&gt;
&lt;li&gt;/var/runtime/index.mjs
Did you forget to add it to "dependencies" in &lt;code&gt;package.json&lt;/code&gt;?
INIT_REPORT Init Duration: 202.73 ms    Phase: invoke   Status: error   Error Type: Runtime.ExitError
Error: Runtime exited with error: exit status 1
Runtime.ExitError`&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Troubleshooting Steps&lt;/strong&gt;
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Dependency Check
First, I double-checked my &lt;code&gt;package.json&lt;/code&gt; file to ensure that express was listed as a dependency. Surprisingly, everything seemed fine.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;code&gt;"dependencies": {&lt;br&gt;
    "express": "^4.18.2"&lt;br&gt;
  },&lt;/code&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Vercel Configuration
Next, I revisited the &lt;code&gt;vercel.json&lt;/code&gt; file. The configuration for serverless functions is crucial here. Previous &lt;code&gt;config&lt;/code&gt; was &lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

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


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  &lt;strong&gt;The Solution&lt;/strong&gt;
&lt;/h2&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

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



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>programming</category>
      <category>react</category>
      <category>javascript</category>
      <category>serverless</category>
    </item>
  </channel>
</rss>
