When trying to make a 'POST' request using the 'fetch' node function, between the frontend and the backend (React Next.js and Django), I got an 'ECONNREFUSED' error.
Backend requests using Postman worked as expected.
Django is on port: 8000 and Next.js is on port: 3000.
It was working until I installed the XCode, Ionic and Capacitor packages (I don't really know if they are the reason I'm getting this error).
Here is the error:
TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11118:11)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(api)/./src/pages/api/account/login.js:18:28)
at async Object.apiResolver (/Users/tomas.leblanc/Dev/HermesApp/frontend/node_modules/next/dist/server/api-utils/node.js:185:9)
at async DevServer.runApi (/Users/tomas.leblanc/Dev/HermesApp/frontend/node_modules/next/dist/server/next-server.js:395:9)
at async Object.fn (/Users/tomas.leblanc/Dev/HermesApp/frontend/node_modules/next/dist/server/base-server.js:496:37)
at async Router.execute (/Users/tomas.leblanc/Dev/HermesApp/frontend/node_modules/next/dist/server/router.js:226:36)
at async DevServer.run (/Users/tomas.leblanc/Dev/HermesApp/frontend/node_modules/next/dist/server/base-server.js:606:29)
at async DevServer.run (/Users/tomas.leblanc/Dev/HermesApp/frontend/node_modules/next/dist/server/dev/next-dev-server.js:450:20)
at async DevServer.handleRequest (/Users/tomas.leblanc/Dev/HermesApp/frontend/node_modules/next/dist/server/base-server.js:321:20) {
cause: Error: connect ECONNREFUSED ::1:8000
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1300:16) {
errno: -61,
code: 'ECONNREFUSED',
syscall: 'connect',
address: '::1',
port: 8000
}
}
Would be nice if someone could help me dealing with this error!
If you need more details or project files, please fill free to ask :D
EDIT1:
If I start the front app, and try to execute the fetch function, it will show the above arrero, but first is gonna show this:
(node:10488) ExperimentalWarning: The Fetch API is an experimental feature. This feature could change at any time
(Use `node --trace-warnings ...` to show where the warning was created)
Shouldn't be the reason though.
EDIT2:
I did downgrade Node.js version from 'v18.11.0' to 'v16.17.1' and now is working!!