Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nx vs Next.js | Environments files loaded in wrong order #7266

Closed
ild0tt0re opened this issue Oct 6, 2021 · 8 comments
Closed

Nx vs Next.js | Environments files loaded in wrong order #7266

ild0tt0re opened this issue Oct 6, 2021 · 8 comments
Labels
outdated scope: nextjs Issues related to NextJS support for Nx type: enhancement

Comments

@ild0tt0re
Copy link

Current Behavior

nx serve command, load .env file in apps/<next-app> two times:

That cause .env file to be loaded in process.env on the first loading (Nx) so during the second loading (Next.js) the order is no longer maintained -> https://github.com/vercel/next.js/blob/canary/packages/next-env/index.ts#L52

i.e: same env var in both .env.development and .env, cause .env to have highest priority

Expected Behavior

The order of Next.js environment variables should be maintained

i.e: same env var in both .env.development and .env, should give to .env.development highest priority

Steps to Reproduce

  1. Create Next.js app
  2. Create all possibles env files supported by Next.js and set in each file an env var with the same key but different value https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
  3. Launchnx serve
  4. the order is not maintained (ie: in process.env. there is .env and not .env.development)

Environment

  Node : 14.17.0
  OS   : darwin x64
  yarn : 1.22.15

  nx : 12.9.0
  @nrwl/angular : Not Found
  @nrwl/cli : 12.9.0
  @nrwl/cypress : 12.9.0
  @nrwl/devkit : 12.9.0
  @nrwl/eslint-plugin-nx : 12.9.0
  @nrwl/express : Not Found
  @nrwl/jest : 12.9.0
  @nrwl/linter : 12.9.0
  @nrwl/nest : Not Found
  @nrwl/next : 12.9.0
  @nrwl/node : Not Found
  @nrwl/nx-cloud : Not Found
  @nrwl/react : 12.9.0
  @nrwl/schematics : Not Found
  @nrwl/tao : 12.9.0
  @nrwl/web : 12.9.0
  @nrwl/workspace : 12.9.0
  @nrwl/storybook : 12.9.0
  @nrwl/gatsby : Not Found
  typescript : 4.3.5
@FrozenPandaz FrozenPandaz added the scope: nextjs Issues related to NextJS support for Nx label Oct 7, 2021
@kirjai
Copy link
Contributor

kirjai commented Oct 18, 2021

hi @ild0tt0re , thanks for opening the issue!

so as you noted, Nx doesn't currently support environment variable files other than those that are mentioned in the docs that you linked to (Docs).

I assume this issue occurs only when you're using env files that Nx doesn't support, like env.development? Meaning, that this doesn't happen when using env.local, for example? If this only happens for env files that Nx doesn't currently support, I'd change this from a bug to an enhancement

@ild0tt0re
Copy link
Author

ild0tt0re commented Oct 19, 2021

hi @ild0tt0re , thanks for opening the issue!

so as you noted, Nx doesn't currently support environment variable files other than those that are mentioned in the docs that you linked to (Docs).

I assume this issue occurs only when you're using env files that Nx doesn't support, like env.development? Meaning, that this doesn't happen when using env.local, for example? If this only happens for env files that Nx doesn't currently support, I'd change this from a bug to an enhancement

Hi @kirjai , thanks for the answer.

Exactly!
Fortunately, the environment variables loading process logic of Nx and Next.js is the same so if Nx can handle also these files would be great because we can use the framework transparently without having any side effects.

@chf007
Copy link

chf007 commented Apr 28, 2022

#ZachJW34/nx-plus#239

Can Nx provide a configuration item to turn off its own dotenv processing, which is completely handled by plugins?

@the1979
Copy link

the1979 commented Jul 28, 2022

+1 for consideration on this. It would be great if it matches the Next.js behaviour.

@kalinchernev
Copy link

Same issue with loading order holds true for nest.js + nx combination. The load order of nx overrides the one of the nest.js config module definition which makes the integration not as smooth as everything else nx does so far.

A configuration option to disable default loader would be welcome.

@kalinchernev
Copy link

And as a follow-up => https://github.com/nrwl/nx/releases/tag/14.8.6

@ndcunningham
Copy link
Contributor

Closing due to no activity and should be working currently.
As of Nx v16.3.0 we are now using the Next.js CLI for our build / server executor.

@github-actions
Copy link

github-actions bot commented Jul 9, 2023

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 9, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated scope: nextjs Issues related to NextJS support for Nx type: enhancement
Projects
None yet
Development

No branches or pull requests

7 participants