Deploying Next.js app with both Node and Python serverless functions
Answered
Cape lion posted this in #help-forum
Cape lionOP
I am trying to add a python endpoint to my existing next.js app. I followed this example: https://github.com/vercel/examples/tree/main/python/nextjs-flask
However, the build for my preview environment on Vercel does not show the python function in the deployment summary. Is there anything I'm missing or how should I try debugging this situation?
However, the build for my preview environment on Vercel does not show the python function in the deployment summary. Is there anything I'm missing or how should I try debugging this situation?
26 Replies
@Cape lion I am trying to add a python endpoint to my existing next.js app. I followed this example: https://github.com/vercel/examples/tree/main/python/nextjs-flask
However, the build for my preview environment on Vercel does not show the python function in the deployment summary. Is there anything I'm missing or how should I try debugging this situation?
I got 500 error too after deploying the template
the error is
the error is
LAMBDA_WARNING: Unhandled exception. The most likely cause is an issue in the function code. However, in rare cases, a Lambda runtime update can cause unexpected function behavior. For functions using managed runtimes, runtime updates can be triggered by a function change, or can be applied automatically. To determine if the runtime has been updated, check the runtime version in the INIT_START log entry. If this error correlates with a change in the runtime version, you may be able to mitigate this error by temporarily rolling back to the previous runtime version. For more information, see https://docs.aws.amazon.com/lambda/latest/dg/runtimes-update.html
[ERROR] Runtime.ImportModuleError: Unable to import module 'vc__handler__python': cannot import name 'url_quote' from 'werkzeug.urls' (/var/task/werkzeug/urls.py)
Traceback (most recent call last):@Cape lion I am trying to add a python endpoint to my existing next.js app. I followed this example: https://github.com/vercel/examples/tree/main/python/nextjs-flask
However, the build for my preview environment on Vercel does not show the python function in the deployment summary. Is there anything I'm missing or how should I try debugging this situation?
I think adding
Werkzeug==2.2.2 to requirements.txt should fix ityes it does fix it
or change Flask version to 3.0.0
Cape lionOP
hmm my requirements txt has
Flask==3.0.2
...
Werkzeug==3.0.1@Cape lion hmm my requirements txt has
Flask==3.0.2
...
Werkzeug==3.0.1
not working with this?
Cape lionOP
yea, i'm thinking this is something to do with Vercel and not Next (my mistake)
numpy==1.24.3
Flask==3.0.0just tested with these and it works
let me try 3.0.2
Cape lionOP
running
vercel build list the app routes at the end and the python route does not show up in that list@Ray let me try 3.0.2
this work too
Cape lionOP
yes and the output directory as well
.vercel/output/functions...but can you access /api/python?
Cape lionOP
in local i can, but in my generated vercel preview environment it's a 404
Cape lionOP
hmm I definitely missed something then -- I tried to add the flask server to my existing next app rather than starting from the template
so I can compare
Cape lionOP
unfortunately, it's a private repo. I did spot a difference though.
the template has
the template has
index.py under /api folder, but my repo has it as /api/some-path/index.pyoh also, my next app is using app router so the path is actually
/app/api/some-path/index.pyyou have to move the
api folder to the rootAnswer
Cape lionOP
that did the trick, thank you!