Next.js Nextjs中的publicRuntimeConfig客户端不工作

Next.js Nextjs中的publicRuntimeConfig客户端不工作,next.js,Next.js,在我的next.config.js中,我有以下配置: module.exports = { publicRuntimeConfig: { // Will be available on both server and client GRAPHQL_URL: process.env.API_URL, }, } 我的脚本如下所示: "build": "next build", &quo

在我的
next.config.js中,我有以下配置:

    module.exports = {
      publicRuntimeConfig: {
        // Will be available on both server and client
        GRAPHQL_URL: process.env.API_URL,
      },
     }
我的脚本如下所示:

"build": "next build",
"start": "API_URL=some-url next start",
现在运行
npm运行start
并在我的代码中使用
{publicRuntimeConfig}=getConfig()


publicRuntimeConfig
包含
GRAPHQL\u URL
服务器端,但它在客户端是一个空对象。

是否使用
getInitialProps
<除非使用
getInitialProps
,否则code>publicRuntimeConfig
将不可用:

依赖publicRuntimeConfig的页面必须使用getInitialProps 选择退出自动静态优化。运行时配置将不起作用 可用于任何页面(或页面中的组件),而无需 getInitialProps