dapr / js-sdk

Dapr SDK for Javascript
Apache License 2.0
192 stars 80 forks source link

Next.js app fails during build with Error: DAPR_SIDECAR_COULD_NOT_BE_STARTED #566

Closed xendren closed 6 months ago

xendren commented 6 months ago

Ask your question here

We are using Next.js for building our react application. We have followed the JavaScript SDK examples for fetching secrets using the Dapr SDK. Everything is working fine in standalone mode, but we are getting the error below when running next build. It appears to be awaiting the sidecar to startup during the build for some reason. I'll post the question on Next.js project as well.

Any help would be appreciated.

"Error: DAPR_SIDECAR_COULD_NOT_BE_STARTED"

shubham1172 commented 6 months ago

Hi @xendren, if it's a front-end application then the SDK won't work. It needs a Node runtime.

Also

It appears to be awaiting the sidecar to startup during the build for some reason

Could you share what commands you're using to start the app (with SDK) and sidecar, and share a minimum reproducible example with logs? Also curious to know, what is this next.js project?

xendren commented 6 months ago

Hi @xendren, if it's a front-end application then the SDK won't work. It needs a Node runtime.

Also

It appears to be awaiting the sidecar to startup during the build for some reason

Could you share what commands you're using to start the app (with SDK) and sidecar, and share a minimum reproducible example with logs? Also curious to know, what is this next.js project?

This is a react app using Next.js framework. This error is occurring during the "next build" command to prepare for deployment, so this isn't even at runtime. Next.js appears to be executing code during the build optimization process.

I have tried installing the Dapr CLI and runtime during the build, but it gets the same error. Oddly, it will only pass the build process if the sidecar is actually running. I'm guessing the Next.js optimization process is doing something it shouldn't. I posted this question in hopes that someone might have some ideas. Our next thing to try is to switch to making the sidecar calls without using the dapr js-SDK, but I was hoping to avoid that if possible.

xendren commented 6 months ago

For anyone else that encounters this problem, we were able to solve it by moving the Dapr client logic to the instrumentation.js source and enabling the instrumentation feature in the Next.js configuration. This feature is used to execute server side code once at startup. Here is a link to the Next.js docs on instrumentation.