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` looks in the wrong directory with `invoke local`

See original GitHub issue

This is an odd quirk in difference in how serverless offline works vs serverless invoke local ... today.

If using the dotenv package, it will look for the .env file in <root>/.env in offline. Alternatively, in invoke local it will look for it in <root>/.esbuild/build/.env instead.

The current working directory for the two methods appears to be different, I think this is caused by this PR: https://github.com/floydspace/serverless-esbuild/pull/122 but I am unsure…

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
mattisdadacommented, Dec 7, 2021

No, it’s only for the developer environment. It’s so you can have a local set of environment variables as a file, once deployed into production the env variables will be set specifically for that environment. So it’s not part of the package or deployment.

If you’re unfamiliar with dotenv, this might help a little bit on why it exists: https://github.com/motdotla/dotenv#faq

0reactions
samchungycommented, Jan 10, 2022

Yeah that’s a good point.

I think that might also be related to how serverless offline works. Since serverless invoke local targets a single specific lambda but with serverless offline we have no idea what lambda will be invoked and we rely on the behaviour of the serverless-offline plugin to control the behaviour.

So like you suggested that might just be a quirk between the two. Bare in mind both implementations do explicitly state that they are not a 100% perfect emulation but a good enough one.

Read more comments on GitHub >

github_iconTop Results From Across the Web

dotenv file is not loading environment variables - Stack Overflow
Turns out I was running my app from my user/ directory with nodemon application_name/. and that was making dotenv look for the .env...
Read more >
Error: ENOENT: no such file or directory, open '.env' · Issue #135
the solution is to use the terminal, run touch .env in your project root folder, a new .env file will be created and...
Read more >
Dotenv - npm
Loads environment variables from .env file. Latest version: 16.0.3, last published: 3 months ago. Start using dotenv in your project by ...
Read more >
Container environment variables - Visual Studio Code
As this example illustrates, containerEnv can reference local variables and ... Otherwise run Dev Containers: Open Folder in Container... to connect to the ......
Read more >
python-dotenv - PyPI
By default, load_dotenv doesn't override existing environment variables. To configure the development environment, add a .env in the root directory of your ...
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