4

In my package.json, I have a build script set to build my next project as follows:

"build": "echo \"$NODE_ENV\" && NODE_ENV=$NODE_ENV next build && npm run build-server",

The output from the command that I get is:

> admin-ui@1.0.0 build /usr/src/admin-ui
> echo "$NODE_ENV" && NODE_ENV=$NODE_ENV next build && npm run build-server

development
Creating an optimized production build ...

The echo outputs development as the value for $NODE_ENV. However, I cannot get that passed to next. It just ignores it.

Using next.js version 9.0.5.

Gezim
  • 7,112
  • 10
  • 62
  • 98
  • what you mean with "I cannot get that passed to next"? that you cant detect the current enviroment inside next app? (ex. inside _document.js) – Nico Jul 01 '20 at 07:09
  • @nico next ignores my value of `NODE_ENV`. – Gezim Jul 01 '20 at 11:21
  • related: https://stackoverflow.com/questions/57408007/nextjs-next-build-with-node-env-development – Ciro Santilli OurBigBook.com May 24 '21 at 16:43
  • According to an [answer on a GitHub issue](https://github.com/vercel/next.js/issues/17032#issuecomment-691506975) using APP_ENV is suggested. That sounds like an ok solution. – Davey Sep 16 '21 at 13:29

1 Answers1

1

next build generates production builds

next dev creates a development build - https://nextjs.org/docs/api-reference/cli#development

Build usually is nomenclature for production builds and dev for a development server.

When you do next build it assumes that its preparing for production and continues to do so.

Ramakay
  • 2,919
  • 1
  • 5
  • 21
  • 5
    This is kind of silly and I definitely believe it shouldn't ignore an explicit setting. I'm building a docker image and that's why I need to build first (prod and dev have the same Dockerfile). – Gezim Jul 01 '20 at 11:22
  • 1
    Note that `NODE_ENV` is used in a [special way](https://stackoverflow.com/questions/57408007/nextjs-next-build-with-node-env-development?noredirect=1&lq=1) in Next.js. (I could not find reliable information on how it behaves, but it definitively has a special meaning.) – kca Sep 27 '21 at 14:38