examples
examples copied to clipboard
nextjs-flask example broken
Running:
npx create-next-app nextjs-flask --example "https://github.com/vercel/examples/tree/main/python/nextjs-flask"
cd nextjs-flask
npm install
npm run dev
results in:
> [email protected] dev
> concurrently "pnpm run next-dev" "pnpm run flask-dev"
[0]
[0] > [email protected] next-dev C:\Users\jgalvan\OneDrive - Managed Network Solutions Inc\Desktop\plsworkflasknextjs\nextjs-flask
[0] > next dev
[0]
[1]
[1] > [email protected] flask-dev C:\Users\jgalvan\OneDrive - Managed Network Solutions Inc\Desktop\plsworkflasknextjs\nextjs-flask
[1] > FLASK_DEBUG=1 pip3 install -r requirements.txt && python3 -m flask --app api/index run -p 5328
[1]
[1] 'FLASK_DEBUG' is not recognized as an internal or external command,
[1] operable program or batch file.
[1] ELIFECYCLE Command failed with exit code 1.
[1] pnpm run flask-dev exited with code 1
[0] - ready started server on 0.0.0.0:3000, url: http://localhost:3000
[0] - event compiled client and server successfully in 7.1s (313 modules)
[0] - wait compiling...
[0] - event compiled client and server successfully in 1140 ms (313 modules)
[0] - wait compiling /page (client and server)...
[0] - event compiled client and server successfully in 7.6s (617 modules)
[0] - wait compiling...
[0] - event compiled successfully in 482 ms (354 modules)
[0] Failed to proxy http://127.0.0.1:5328/api/python Error: connect ECONNREFUSED 127.0.0.1:5328
[0] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) {
[0] errno: -4078,
[0] code: 'ECONNREFUSED',
[0] syscall: 'connect',
[0] address: '127.0.0.1',
[0] port: 5328
[0] }
[0] - wait compiling /_error (client and server)...
[0] - error Error: connect ECONNREFUSED 127.0.0.1:5328
[0] at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1495:16) {
[0] errno: -4078,
[0] code: 'ECONNREFUSED',
[0] syscall: 'connect',
[0] address: '127.0.0.1',
[0] port: 5328
[0] }
[0] - event compiled client and server successfully in 2.7s (595 modules)
I've also tried this another time after --force
fixing the vulnerabilities.
:(
I've found that I am able to get this working by running the npm run next-dev
and npm run flask-dev
commands by themselves in two different terminals. I can also package these commands in a single Python script and thread it to get it working too. Does this sound weird?
I managed to resolve this by updating the versions of numpy and Flask in the requirements.txt:
numpy==1.26.0
Flask==3.0.1
Before I tried that, I also installed pnpm, but not sure if that's required if you just update the versions above.
npm install -g pnpm
anyone can solve this ?
i have solve this with remove FLASK_DEBUG=1 "flask-dev": "pip3 install -r requirements.txt && python3 -m flask --app api/index run -p 5328",
Hey guys, I could run it but I had to install and update lot of things (I've been asking copilot pasting the errors of the console and he guided me)
My python version:
3.11.3
My requirements.txt:
numpy==1.26.4 Flask==3.0.1
My command to run:
pip install -r requirements.txt && python -m flask --app api/index run -p 5328
I'm using Windows and I also had to install choco & cmake
And lastly run this commands to create an environment
python -m venv env source env/Scripts/activate pip install -r requirements.txt
Just need to install pnpm:
npm install -g pnpm
But first, be sure you have done:
FIrst npm install
Install a virtual environment and python dependencies (be sure to have Flask and numpy to last versions modifiying requirements.txt): python -m venv env && source env/bin/activate && pip install -r requirements.txt
Finally, just npm run dev
(internally runs the python3 -m flask stuff).
What about production ? Someone already deploy this on Vercel without any issue ?
(Edit) Find that it's broken in this #831, i test it myself and still the case.
I managed to get it working in production by modifying the "start" command in package.json to:
"start": "concurrently "next start" "PYTHONPATH=./api:$PYTHONPATH api/venv/bin/gunicorn -w 4 -b :5328 api.index:app"" This setup appears to be functioning correctly.
Additionally, it was necessary to update next.config.js to ensure it continues to accept requests in the production environment. Therefore, I modified the line from /api/ to 'http://127.0.0.1:5328/api/:path*'.
just remove the version numbers in requirements.txt , it will default to the latest version. that worked for me.
Note: i've added also venv but don't know if that was related or not.
@nacx-cg actually the issue when i'm building the project.
Try everything but still.
@YvesleCurseur This is solved by adjusting node version to 18.x in the vercel Project Settings check: https://github.com/orgs/vercel/discussions/6287#discussioncomment-8974182
Thank's @nacx-cg ! Yeah i kept the 20.x one, just switched and it's working fine now.
I'm also facing the same issue while running a project on Windows. I resolved it by setting FLASK_DEBUG=1 in the terminal and removing it from the flask-dev command. The final flask-dev command is:
"flask-dev": "pip3 install -r requirements.txt && python3 -m flask --app api/index run -p 5328"
For more info, you can check this Stack Overflow post.