ParseError: XMLHttpRequest failed: "Unable to connect to the Parse API" Docker

hi, i am trying to build my nextjs app that uses ISR and the pages gets dynamic data from moralis (https://lfeeagqdih7x.usemoralis.com:2053/server). The app builds fine locally, but it’s timing out when i try to build it in docker for rolling out the application. Has anyone run into this issue? Thx in advance.

Here is the error I am getting when I try to build the docker image:
#0 215.2 info - Collecting page data…
#0 260.7 /app/node_modules/moralis/lib/node/RESTController.js:430
#0 260.7 error = new _ParseError.default(_ParseError.default.CONNECTION_FAILED, XMLHttpRequest failed: ${JSON.stringify(message)});
#0 260.7 ^
#0 260.7
#0 260.7 ParseError: XMLHttpRequest failed: β€œUnable to connect to the Parse API”
#0 260.7 at handleError (/app/node_modules/moralis/lib/node/RESTController.js:430:15)
#0 260.7 at processTicksAndRejections (node:internal/process/task_queues:96:5)
#0 260.7 at async Function.initPlugins (/app/node_modules/moralis/lib/node/MoralisWeb3.js:441:40)
#0 260.7 at async Function.start (/app/node_modules/moralis/lib/node/Parse.js:157:7) {
#0 260.7 code: 100
#0 260.7 }

when I build the project without docker, everything works perfectly:
Page Size First Load JS
β”Œ β—‹ / (6156 ms) 1.32 kB 1.66 MB
β”œ /_app 0 B 1.66 MB
β”œ β—‹ /404 195 B 1.66 MB
β”œ β—‹ /account (6295 ms) 7.84 kB 1.76 MB
β”œ ● /admin (ISR: 10 Seconds) (1366 ms) 642 B 1.69 MB
β”œ Ξ» /api/requestsForMint/admin/approveRequest 0 B 1.66 MB
β”œ Ξ» /api/requestsForMint/admin/getAllPendingRequests 0 B 1.66 MB
β”œ Ξ» /api/requestsForMint/admin/getAllRequests 0 B 1.66 MB
β”œ Ξ» /api/requestsForMint/admin/rejectRequest 0 B 1.66 MB
β”œ Ξ» /api/requestsForMint/user/getRequestById 0 B 1.66 MB
β”œ Ξ» /api/requestsForMint/user/getUserRequests 0 B 1.66 MB
β”œ Ξ» /api/requestsForMint/user/mintSuccessful 0 B 1.66 MB
β”œ Ξ» /api/requestsForMint/user/newRequest 0 B 1.66 MB
β”œ β—‹ /create (6299 ms) 15.1 kB 1.71 MB
β”œ ● /marketplace (ISR: 10 Seconds) (9144 ms) 11 kB 1.76 MB
β”œ ● /marketplace/[itemId] (ISR: 60 Seconds) (27693 ms) 3.73 kB 1.75 MB
β”œ β”œ /marketplace/6 (6186 ms)
β”œ β”œ /marketplace/1 (5700 ms)
β”œ β”œ /marketplace/2 (5380 ms)
β”œ β”œ /marketplace/7 (5261 ms)
β”œ β”” /marketplace/3 (5166 ms)
β”œ ● /requests/[itemId] (ISR: 60 Seconds) (19894 ms) 2.48 kB 1.67 MB
β”œ β”œ /requests/DHq31vaQWEdioVOWfnEuuRO2 (1530 ms)
β”œ β”œ /requests/kofCsBLCmsXFEwV3AeLmq9ni (1528 ms)
β”œ β”œ /requests/feLcCRtFNK85qwLoYGU9gdBY (1489 ms)
β”œ β”œ /requests/14yE5sPjvAHwwN6yAxHcBAGZ (1455 ms)
β”œ β”œ /requests/IC15o6FP7NsNl2o4sUDDZHNY (1395 ms)
β”œ β”œ /requests/aiVAmmoHiifYAKvJeSIzpll8 (1369 ms)
β”œ β”œ /requests/Ol6FVVdBEud2sdxnWWoX7qZB (1294 ms)
β”œ β”” [+11 more paths] (avg 894 ms)
β”” β—‹ /staking (6311 ms) 30.4 kB 1.77 MB

  • First Load JS shared by all 1.66 MB
    β”œ chunks/framework-bb5c596eafb42b22.js 42.1 kB
    β”œ chunks/main-80a5734f487c3b7a.js 30.8 kB
    β”œ chunks/pages/_app-5e65efbceab5011c.js 1.59 MB
    β”œ chunks/webpack-a838eec304da568e.js 2.15 kB
    β”” css/fd22a7640824eb25.css 575 B

Ξ» (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
β—‹ (Static) automatically rendered as static HTML (uses no initial props)
● (SSG) automatically generated as static HTML + JSON (uses getStaticProps)
(ISR) incremental static regeneration (uses revalidate in getStaticProps)

:sparkles: Done in 124.77s.

Why would it need to connect to parse server at build time?

That’s a great question. Anyone from moralis who has done builds on docker who might know?

Regarding the why at build time. Looks like you are using nextjs, probably it is generating statically generated pages or prepares server side used props that are fetched with privileged requests at build time and then served at runtime to the client upon request of that page / route.

Regarding the connectivity issue within the containerized environment, you can try to replace the build process with simple shell execution of ping requests to 8.8.8.8 or 1.1.1.1 to ensure that the application actually has internet access. Alternatively you might want to check configuration options for the moralis credentials that could default to something unexpected.