I am inquiring about a query regarding my Next.js project.
In my project configuration, I have set it to be built in standalone mode for deployment. You can find more information on this link.
experimental: {
outputStandalone: true
}
As expected, utilizing this feature generates a standalone folder with a server.js
.
The main complication arises from the utilization of an environment variable in my source code named NEXT_PUBLIC_API_BASE_URL
.
During development mode (using next serve
), everything functions properly.
However, when launching the generated standalone file (via node server.js
), it fails to work.
It appears that the file is being loaded on the "server side." Upon logging its value in
.next/standalone/server/pages/_app.js
, the correct value is displayed in the node console.
Nonetheless, it seems like Next.js utilizes files located under .next/static/chunks/pages/
and another app.js which does not appear to access process.env (on the browser side).
My assumption was that by prefixing my env var with NEXT_PUBLIC
, it should function accordingly; however, this does not seem to be the case.
Do you have any insights into how this operates?