Next.js: Cannot read property 'publicRuntimeConfig' of undefined when updating from Next 7 to Next 9

Created on 23 Jul 2019  路  2Comments  路  Source: vercel/next.js

Bug report

Describe the bug

I upgraded from Next 7.0.3 -> Next 9.0.2. Huge jump for sure, so I imagined there would be issues. I am basing all of my configs based on the universal-runtime example.

My next.config.js:

const withPlugins = require('next-compose-plugins');
const withCSS = require('@zeit/next-css');
// This handles Next.js + Monorepo support
const withTM = require('@weco/next-plugin-transpile-modules');

module.exports = withPlugins([withTM, withCSS], {
  // Monorepo
  transpileModules: ['@company'],
  // Env
  publicRuntimeConfig: {
    env: process.env.NODE_ENV,
    prefix: '/video'
  },
  // Polyfills
  webpack(cfg) {
    const originalEntry = cfg.entry;
    cfg.entry = async () => {
      const entries = await originalEntry();

      if (entries['main.js'] && !entries['main.js'].includes('./client/polyfills.js')) {
        entries['main.js'].unshift('./client/polyfills.js');
      }

      return entries;
    };

    return cfg;
  }
});

and my package.json scripts look like:

"scripts": {
    "dev": "SET NODE_ENV=dev& node server/server.js",
    "build": "next build",
    "development": "NODE_ENV=development npm start",
    "staging": "NODE_ENV=staging npm start",
    "prod": "NODE_ENV=prod npm start",
    "start": "node server/server.js",
    "lint": "eslint . --ext .js --fix --ignore-pattern 'node_modules/**'"
  }

I used throughout my components this type of import logic:

import getConfig from 'next/config';

const { publicRuntimeConfig } = getConfig();
const { env } = publicRuntimeConfig;

I reverted back to Next 7, and everything is working fine again, but whenever I upgraded to Next 8 or 9, I get Cannot read property 'publicRuntimeConfig' of undefined for any components or functions that try to tap into that property.

Thanks a ton for any help!

Most helpful comment

This seems to be related:
https://github.com/zeit/next.js/issues/7713
I've experienced this when running next build inside a docker container in 9.0.0, and upgrading to 9.0.2 fixed it.

All 2 comments

A full reproduction is needed to investigate. Please add a repository.

This seems to be related:
https://github.com/zeit/next.js/issues/7713
I've experienced this when running next build inside a docker container in 9.0.0, and upgrading to 9.0.2 fixed it.

Was this page helpful?
0 / 5 - 0 ratings