Search code examples
expressdeploymentvercel

Problem deploy Express.js to Vercel 500: INTERNAL_SERVER_ERROR


when I want to deploy my Express.js to Vercel I get error 500: INTERNAL_SERVER_ERROR but when I run on localhost everything goes fine, but now I get the following error when deploying to Vercel can anyone help me?

enter image description here

That's an error from my website page

this is my project folder structure enter image description here

and this is the code from vercel.json

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

and this is my package.json code

{
  "name": "Backend-API",
  "version": "1.0.0",
  "description": "Backend-API-Express",
  "main": "./index.js",
  "engines": {
    "node": "18.x"
  },
  "scripts": {
    "start": "node index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "bcryptjs": "^2.4.3",
    "body-parser": "^1.19.0",
    "cors": "^2.8.5",
    "dotenv": "^10.0.0",
    "excel4node": "^1.8.0",
    "express": "^4.18.2",
    "express-validator": "^6.12.2",
    "fs": "0.0.1-security",
    "helmet": "^6.0.1",
    "http-status-codes": "^2.1.4",
    "jsonwebtoken": "^8.5.1",
    "method-override": "^3.0.0",
    "multer": "^1.4.5-lts.1",
    "nodemon": "^2.0.14",
    "passport": "^0.6.0",
    "passport-jwt": "^4.0.0",
    "passport-local": "^1.0.0",
    "path": "^0.12.7",
    "pg": "^8.7.1",
    "pg-hstore": "^2.3.4",
    "prettier": "^3.0.0",
    "sequelize": "^6.27.0",
    "uuid": "^9.0.0",
    "xlsx": "^0.18.5"
  },
  "devDependencies": {
    "sequelize-cli": "^6.5.2",
    "webpack": "^5.90.0",
    "webpack-cli": "^5.1.4"
  }
}

someone please help me


Solution

  • from the docs:

    Standalone Express

    You can also create a standalone Express.js app with Vercel. First, create a file index.js and add it to an /api folder. This is similar to the app.js file in serverful Express.js applications. The /api directory is where we'll add our Serverless Functions.

    and you do not need this in express app

     app.use(express.static('public'))
    

    place static assets in the next.js' public folder