添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

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.

Server.js

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');
require('dotenv').config()
  // Middleware
  const saveLoggedInUserMiddleware = require('../Middleware/SaveLoggedInUserMiddleware');
  const hostValidationMiddleware = require('../Middleware/HostValidationMiddleware');
  const sessionValidationMiddleware = require('../Middleware/SessionValidationMiddleware');
  const updateUserDataMiddleware = require('../Middleware/UpdateUserDataMiddleware');
  //Routers
  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'); 
  connectToDB();
  // 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
  app.use(
    expressSession({
          secret: process.env.SESSION_SECRET,
          resave: false,
          saveUninitialized: false,
  app.use('/fetchUserInvoices', limiter);
app.use(express.json());
//app.use(cors());
app.use(express.static('./build'));
app.use('/.netlify/functions/', hostValidationMiddleware, sessionValidationMiddleware, StoreInvoiceRouter);
app.use('/.netlify/functions/', saveLoggedInUserMiddleware, UserInvoicesRouter);
app.use('/.netlify/functions/', updateUserDataMiddleware, UpdateUserProfileRouter);
app.get('*', async (req,res) => {
  res.sendFile('/Users/augustshah/Documents/Coding-Tools-new/Projects/Payment-Dashboard/build/index.html');
  // 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
  updateDBCall(); 
        "add-react-displayname",
        "@babel/plugin-proposal-class-properties",
        "@babel/plugin-proposal-object-rest-spread",
        "@babel/transform-runtime"
              

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:

  • Your netlify site name
  • Your function name
  • Your most recent deploy log
  • Any additional debugging steps you have taken since you last posted
  • Thank you :slight_smile: