其實在next.config.js裡加env,這個值會在build的時候被用上。 const withPlugins = require("next-compose-plugins"); const css = require("@zeit/next-css"); // require("dotenv").config(); const nextConfig = { target: "serverless", webpack(config) { config.module.rules.push({ test: /\.(png|svg|eot|otf|ttf|woff|woff2)$/, use: { loader: "url-loader", options: { limit: 8192, publicPath: "/_next/static/", outputPath: "static/", name: "[name].[ext]" } } }); return config; }, env: { API_HOST: "http://www.localhost:3030" } // publicRuntimeConfig: { // // Will be available on both server and client // API_HOST: process.env.API_HOST // } }; module.exports = withPlugins([[css]], nextConfig); 這樣更好。 注意使用"now"來部署是serverless,所以用不了publicRuntimeConfig。