question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotenv loaded unexpectedly when useNx: true

See original GitHub issue

So with Lerna 5.6 with useNX: true or Lerna 6, we’re seeing a few test cases fail. They all seem to be failing because running the test target with nx enabled seems to be automagically loading an existing .env file in the directory where the tests run

I’m starting to think this behavior is from nx itself, maybe because of this:

https://github.com/nrwl/nx/blob/a66a549e4bb2bca1c63add7ed40396228c3cbcbb/packages/nx/src/tasks-runner/forked-process-task-runner.ts#L278-L279

Is there a way to disable this behavior? It seems a little overly magical, and is arguably an undocumented breaking change.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
JamesHenrycommented, Oct 14, 2022

Thanks for reporting this @wyardley I have removed the discussion to keep things focused here.

We will update the release notes for v6 to highlight this change in default behaviour, and also give you a way to disable the automatic .env loading given that’s desirable for your setup.

That flag will go out today and I will close this issue once it’s ready.

1reaction
JamesHenrycommented, Oct 14, 2022

@wyardley in your lerna.json you can specify the flag for the lerna run command:

lerna.json

{
  "command": {
    "run": {
      "loadEnvFiles": false
    }
  }
}
Read more comments on GitHub >

github_iconTop Results From Across the Web

dotenv file is not loading environment variables - Stack Overflow
In my case I created one file in Controller folder and tried to output the require('dotenv').config() --> It was showing me "c:\users\..\controller\.env".
Read more >
motdotla/dotenv: Loads environment variables from .env for ...
dotenv. Dotenv is a zero-dependency module that loads environment variables from a .env file into process.env . Storing configuration in the environment ...
Read more >
How to use the dotenv.load function in dotenv - Snyk
To help you get started, we've selected a few dotenv.load examples, ... package.json'); require('dotenv').load({ silent: true }); const config = { all: ...
Read more >
dotenv-webpack - npm
A simple webpack plugin to support dotenv.. Latest version: 8.0.1, last published: 4 months ago. Start using dotenv-webpack in your project ...
Read more >
Env Variables and Modes - Vite
You may see errors like Missing Semicolon or Unexpected token in this case, ... Vite uses dotenv to load additional environment variables from...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found