Home > Net >  NextJS Static Export Specify .env
NextJS Static Export Specify .env

Time:04-11

I have a NextJS app with a Django backend. The NextJS app is statically exported which the Django app redirects too.

When exporting, NextJS uses .env.production by default, however when developing locally I'd prefer it to use .env.development however I can't figure out how to specify that.

When running via npm run dev it uses the proper .env however there is limited info on if this is even possible to choose for the static export - I've just been switching the contents of the files as needed.

Thank you in advance!

CodePudding user response:

When the command next dev (npm run dev) is run, Next.js sets the NODE_ENV environment variable to development (production for anything else, e.g., export) and will load the following files in top-to-bottom order:

  1. .env.development.local
  2. .env.local
  3. .env.development
  4. .env

So there's no need to specify that .env.development should be used — it just needs to exist in your project's root directory.

.env.local gets loaded in both development and production environments, but not in test.

.env gets loaded in all three environments.

Variables in .env*.local will override the same variables in .env, .env.development, and .env.production.

CodePudding user response:

When you run next dev script, next.js will load the environment variables from .env.development

If you run next start script next.js will load the envrionment variables from .env.production

Next.js does not use .env.production by default it uses .env.local by default. .env.local will override anything on the .development or .production files.

  • Related