Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nextjs-flask example broken #816

Open
joshgalvan opened this issue Oct 30, 2023 · 13 comments
Open

nextjs-flask example broken #816

joshgalvan opened this issue Oct 30, 2023 · 13 comments

Comments

@joshgalvan
Copy link

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:

> next-flask@0.1.0 dev
> concurrently "pnpm run next-dev" "pnpm run flask-dev"

[0]
[0] > next-flask@0.1.0 next-dev C:\Users\jgalvan\OneDrive - Managed Network Solutions Inc\Desktop\plsworkflasknextjs\nextjs-flask
[0] > next dev
[0]
[1]
[1] > next-flask@0.1.0 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.

:(

@joshgalvan
Copy link
Author

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?

@cindango
Copy link

cindango commented Feb 1, 2024

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

@zxczxcdev
Copy link

anyone can solve this ?

@zxczxcdev
Copy link

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",

@farichieri
Copy link

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

@jesusizq
Copy link

jesusizq commented Mar 21, 2024

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).

@YvesleCurseur
Copy link

YvesleCurseur commented Apr 4, 2024

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.

@nacx-cg
Copy link

nacx-cg commented Apr 5, 2024

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*'.

@sorydi3
Copy link

sorydi3 commented Apr 6, 2024

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.
Screenshot 2024-04-06 at 11 28 59

@YvesleCurseur
Copy link

@nacx-cg actually the issue when i'm building the project.
Try everything but still.
image

@nacx-cg
Copy link

nacx-cg commented Apr 8, 2024

@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

@YvesleCurseur
Copy link

YvesleCurseur commented Apr 9, 2024

Thank's @nacx-cg ! Yeah i kept the 20.x one, just switched and it's working fine now.

@iamharshad
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants