Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
I am deploying a node project that uses next.js to openshift where I set the environment variable MY_ENV. I have added the
publicRuntimeConfig
configuration to next.config.js to access it client side. It works in my local but when its containerized and deployed
publicRuntimeConfig
is
undefined
.
Here is my configuration from next.config.js
module.exports = {
publicRuntimeConfig: { // Will be available on both server and client
isProd: process.env.MY_ENV ? process.env.MY_ENV.includes('prod'): false,
isStaging: process.env.MY_ENV ? process.env.MY_ENV.includes('staging') : false
webpack: (config, { dev }) => {
const eslintRule = {
test: /\.js$/,
enforce: 'pre',
exclude: /node_modules/,
loader: 'eslint-loader',
options: {
emitWarning: dev,
const cssRule = {
test: /\.css$/,
use: {
loader: 'css-loader',
options: {
sourceMap: false,
minimize: true,
config.node = {
fs: 'empty'
config.module.rules.push(eslintRule);
config.module.rules.push(cssRule);
return config;
This is how I am trying to get the publicRuntimeConfig on my pages.
import getConfig from 'next/config';
const { publicRuntimeConfig } = getConfig();
console.log(publicRuntimeConfig.isProd); //publicRuntimeConfig is undefined here.
Any help is appreciated.
UPDATE/FIX
publicRuntimeConfig
was undefined in higher environments because it was not part of the package that was getting deployed.
const { publicRuntimeConfig } = getConfig();
const isProd = publicRuntimeConfig.isProd || false;
const isStaging = publicRuntimeConfig. isStaging || false;
return { isProd, isStaging }
const env = getNodeEnv()
console.log(env)
–
–
–
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.