I have a question about my Next.js project.
I have configured my project to be build over the standalone mode for the deployment
experimental: {
outputStandalone: true
}
Using this, it generates me a standalone folder with a server.js
like expected.
The main issue is that I am using an env variable in my sources, called NEXT_PUBLIC_API_BASE_URL
When I start my project in development mode (using next serve
), it works fine.
But when I start the standalone generated file (using node server.js
) it does not work.
It seems that the file is loaded on the "server side", when I console.log
its value in the .next/standalone/server/pages/_app.js
it shows the right value in the node console.
But it looks like next is using files under .next/static/chunks/pages/
and an other app.js that does not seem to access process.env (on browser side).
I thought that prefixing my env var with NEXT_PUBLIC
was meant to work this way, it seems not.
Any idea on how it works there?
On your build server, create the file name ".env" and put all of your environments.
NEXT_PUBLIC_API_BASE_URL=https://api.example.com
please refer Docs
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.