1

I'm try to deploy my Node.js express app to vercel, But i'm getting this error "This serverless function has crashed." I don't understand what's the problem.

I have an index.js file in the root project folder, Initial the app with routes and starts to listen... and it's working on vercel.

But when i'm trying to connect my Sequelize Database like this:

./api/db/index.js

const {Sequelize, DataTypes} = require("sequelize");
const sequelize = new Sequelize(
                        process.env.DATABASE_NAME, 
                        process.env.MYSQL_USER, 
                        process.env.MYSQL_PASSWORD,
                        {
                          host: process.env.DATABASE_HOST,
                          dialect: 'mysql',
                          dialectOptions: {
                          ssl: {
                              rejectUnauthorized: true,
                          },
                        },
                        define: {
                            timestamps: false
                        }
});

Locally it works but on vercel it throws an error of "This Serverless Function has crashed"

Can someone help me figure it out?

I'm trying to deploy to vercel a very early stage node.js app just to check. But I get an error "This serverless function has crashed."

1
  • See my answer. /api is reserved for serverless functions on Vercel Commented Jun 1, 2023 at 20:31

1 Answer 1

0

I assume you are already familiar with this page: https://vercel.com/guides/using-express-with-vercel which recommends that if you want to deploy an express API, you should deploy it as a serverless app. There are limitations when you do so and the page describes them fairly well. Since you are using a database, you should look into connection pooling. Alternatively, you can use serverless-friendly databases. With this in mind, if you are trying to deploy a serverless express API and you come across this issue, here is what I can suggest:

If you click on your deployment, you will see a Logs tab which will provide you with more information on exactly what is wrong. Most likely the issue is Vercel being unable to guarantee your dialect module. This was the case for me. However, my issue was with postgres, keep that in mind. Reference: https://github.com/orgs/vercel/discussions/234#discussioncomment-5980199

Sign up to request clarification or add additional context in comments.

Comments

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.