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.

Tests do not load .env or serverless.yml variables

See original GitHub issue

On newest release when running npm test which runs serverless-bundle test environment variables from serverless.yml

  name: aws
  runtime: nodejs10.x
  stage: dev
  region: us-east-1
    TEST: "value"

or from .env file


This issue was noticed in the serverless-bundle package and noted by @Vadorequest

Using his solution I was able to load .env variables by adding the following to the package.json

"jest": {
    "setupFilesAfterEnv": [


    path: './.env'

if (process.env.NODE_ENV !== 'test') {
    throw Error('Non-test environment');

severless-bundle test should load serverless.yml environment variables

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

jayaircommented, Feb 23, 2020

@jeff-kilbride Good catch, let me update the sample in the comment.

jayaircommented, Oct 26, 2019

Oh good catch. Yeah I’ll have a look at how to do this in the serverless-bundle plugin.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Resolution of environment variables
The framework loads variables from only one .env file (if stage-specific .env is found, default .env is not loaded); The framework does not...
Read more >
How to get environment variables defined in serverless.yml ...
Make the tests exec sls invoke - this will work but would mean that the code cannot be debugged, I won't know the...
Read more >
Serverless Environment Variables - A Comprehensive Guide
Environments Variables in serverless.yml vs Environment Variables in your Serverless functions. If Serverless vs. serverless was not ...
Read more >
Load Secrets from .env
We are using the serverless-dotenv-plugin to load these as an environment variable when our Lambda function runs locally. This allows us to reference...
Read more >
Manage Serverless Environment Variables Per Stage
Not only can you live test functions locally by simulating events, but you can ... How do we configure our serverless.yml to do...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found