Next.js: Zeit.Now - Next build crashes when using "env" in next.config.js instead of publicRuntimeConfig

Created on 30 Sep 2019  Â·  5Comments  Â·  Source: vercel/next.js

Bug report

Describe the bug

I'm using Zeit.Now and I was using publicRuntimeConfig in next.config.js just fine until I deployed, which yield Cannot use publicRuntimeConfig with target=serverless. The reasons is there but when I replace my publicRuntimeConfig with env, the process hangs indefinitely with the cryptic error at getBaseWebpackConfig (/Users/vadorequest/dev/TFP/node_modules/next/dist/build/webpack-config.js:91:95)

To Reproduce

Replace publicRuntimeConfig with env in next.config.js and run now dev

Expected behavior

Should build properly like https://github.com/zeit/next.js#build-time-configuration states.

Screenshots

image

System information

  • OS: [e.g. macOS, Windows] MacOS
  • Version of Next.js: 9.0.7

Additional info

Here is my next.config.js

require('dotenv').config({ path: '.env' });

console.debug(`Building Next with NODE_ENV="${process.env.NODE_ENV}"`);

module.exports = (phase, { defaultConfig }) => {
  return {
    env: { // See https://github.com/zeit/next.js#build-time-configuration
      ORGANISATION_NAME: process.env.ORGANISATION_NAME,
      NODE_ENV: process.env.NODE_ENV, // XXX Used in utils/env
      GRAPHCMS_CACHE_ENDPOINT: process.env.GRAPHCMS_CACHE_ENDPOINT,
    },
    webpack: config => {
      // Fixes npm packages that depend on `fs` module
      config.node = {
        fs: 'empty',
      };

      return config;
    },
  };
};

Most helpful comment

Yep! The error is now being surfaced. Thank you for reporting!

All 5 comments

I got a more detailed stack trace by doing the following:

 ↵ 1  yarn dev
yarn run v1.17.3
$ next dev --port 8888
[ wait ]  starting the development server ...
[ info ]  waiting on http://localhost:8888 ...
Building Next with NODE_ENV="development"
Error: The key "NODE_ENV" under "env" in next.config.js is not allowed. https://err.sh/zeit/next.js/env-key-not-allowed
    at webpackConfig.plugins._webpack.default.DefinePlugin.Object.keys.reduce (/Users/vadorequest/dev/TFP/node_modules/next/dist/build/webpack-config.js:91:161)
    at Array.reduce (<anonymous>)
    at getBaseWebpackConfig (/Users/vadorequest/dev/TFP/node_modules/next/dist/build/webpack-config.js:91:95)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Removing NODE_ENV: process.env.NODE_ENV from the file did fix the issue. Launching with the beta now dev command was hiding a self-explanatory error.

Thanks for reporting!

It's unfortunate that now dev didn't properly render the error and instead hid it away. As we speak, my team is working on a more refined version of the output, which simply relays exactly what your development tool is printing, without hiding lines away.

I'll let you know once it has launched!

@leo I guess we should close this? I don't know if the CLI was improved since then.

Yep! The error is now being surfaced. Thank you for reporting!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

renatorib picture renatorib  Â·  3Comments

formula349 picture formula349  Â·  3Comments

YarivGilad picture YarivGilad  Â·  3Comments

timneutkens picture timneutkens  Â·  3Comments

flybayer picture flybayer  Â·  3Comments