Support Forums

Encountering error ReferenceError: regeneratorRuntime is not defined for Expressjs API on netlify

Good Afternoon,
I have a react app hosted on Netlify and have converted my Expressjs API backend to be serverless for use with Netlify functions. Right now I am running into the below error:

502: ReferenceError: regeneratorRuntime is not defined", " at /var/task/server.js"

Server.js is the main API file that imports my middleware.
I have installed the babel regnerator plugin and added it to my babel file as well as importing it on the top of my Server.js file. I am not sure what else to do as I am new to the netlify platform.


import "core-js/stable";
import "regenerator-runtime/runtime";
const express = require('express');
var expressSession = require('express-session');
const cors = require('cors');
const path = require('path');
const app = express();
const axios = require('axios');
const mongoose = require('mongoose');
const rateLimit = require("express-rate-limit");
const serverless = require('serverless-http');

  // Middleware
  const saveLoggedInUserMiddleware = require('../Middleware/SaveLoggedInUserMiddleware');
  const hostValidationMiddleware = require('../Middleware/HostValidationMiddleware');
  const sessionValidationMiddleware = require('../Middleware/SessionValidationMiddleware');
  const updateUserDataMiddleware = require('../Middleware/UpdateUserDataMiddleware');

  const StoreInvoiceRouter = require('../Routes/Store-Update-Invoices');
  const UserInvoicesRouter = require('../Routes/GetUserInvoices');
  const UpdateUserProfileRouter = require('../Routes/UpdateUserProfile');

async function connectToDB() {
  // Database 
  await mongoose.connect(process.env.mongo_url, { useNewUrlParser: true, useUnifiedTopology: true },  () => {
    console.log('[connectToDB]: Connected to DB'); 

  // Implemented a rate limiter which is a TEMPORARY FIX for the infinite loop by the useEffect
  const limiter = rateLimit({
    windowMs: .1 * 60 * 1000, // 10 seconds limit
    max: 4 

  // Creating the session in order to save user data to req.session
          secret: process.env.SESSION_SECRET,
          resave: false,
          saveUninitialized: false,
  app.use('/fetchUserInvoices', limiter);
app.use('/.netlify/functions/', hostValidationMiddleware, sessionValidationMiddleware, StoreInvoiceRouter);
app.use('/.netlify/functions/', saveLoggedInUserMiddleware, UserInvoicesRouter);
app.use('/.netlify/functions/', updateUserDataMiddleware, UpdateUserProfileRouter);

app.get('*', async (req,res) => {


  // Function makes call to endpoint that runs deletion login, this allows the client to only have to be refreshed once to
  // render changes on the frontend.
  async function updateDBCall() {
    const url = `${process.env.REACT_APP_STORE_INVOICES}`;
    const axiosConfig = {
      method: 'get',
      await  axios(axiosConfig).catch((e) => {console.log(e)});
      console.log('[updateDBCall]: Executed call to STORE_INVOICES')


  // Supporting functions

  app.listen(process.env.PORT || 8080, () => {
  console.log(`Server listening on 8080`);
  module.exports.handler = serverless(app);


module.exports = api => {
    return {
      presets: [
      plugins: [

Hey there, @augdog97 :wave:

Thanks for reaching out, and welcome to the Netlify Forums! We appreciate your patience. It looks like your thread has been quiet since you last posted; are you still encountering this error?

If so, can you please share the following:

  1. Your netlify site name
  2. Your function name
  3. Your most recent deploy log
  4. Any additional debugging steps you have taken since you last posted

Thank you :slight_smile:

I actually solved this issue myself. I dont have a clear solution though as I tried many different things such as changing my webpack config, babel config, etc.