[英]Next.js standalone not reading env file
I have a question about my Next.js project.我对我的 Next.js 项目有疑问。
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.使用它,它会为我生成一个带有预期的server.js
的独立文件夹。
The main issue is that I am using an env variable in my sources, called NEXT_PUBLIC_API_BASE_URL
主要问题是我在源代码中使用了一个环境变量,称为NEXT_PUBLIC_API_BASE_URL
When I start my project in development mode (using next serve
), it works fine.当我以开发模式(使用next serve
)启动我的项目时,它工作正常。
But when I start the standalone generated file (using node server.js
) it does not work.但是当我启动独立生成的文件(使用node server.js
)它不起作用。
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.似乎该文件是在“服务器端”加载的,当我在.next/standalone/server/pages/_app.js
中console.log
它的值时,它在节点控制台中显示了正确的值。
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).但看起来下一个正在使用.next/static/chunks/pages/
下的文件和另一个似乎无法访问 process.env 的 app.js(在浏览器端)。
I thought that prefixing my env var with NEXT_PUBLIC
was meant to work this way, it seems not.我认为在我的 env var 前面加上NEXT_PUBLIC
是为了以这种方式工作,但似乎不是。
Any idea on how it works there?关于它如何在那里工作的任何想法?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.