Vercel: Cannot import other functions with Python Serverless API

Viewed 527

I am trying to import helper functions into my Serverless Flask Api but am unable to do so with Vercel using the vercel dev command.

My folder structure is:

api
  _utils/
    common.py
  app.py

However, when I try to import my helper function into my app.py file I get an error saying module cannot be found.

Below is sample code from my app.py

from flask import Flask, Response
from _utils.common import helper_function
app = Flask(__name__)
1 Answers

I moved my _utils file to the root of my project and now in my api/index.py I import as follows

from _utils.common import helper_function

My vercel.json file looks like:

{
  "routes": [
    {
      "src": "/api/(.*)",
      "dest": "api/index.py"
    }
  ]
}
Related