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.

.env variables behave different between local and Vercel

See original GitHub issue

Bug report

Describe the bug

Environment variables cannot be accessed in api routes when deployed on Vercel using the latest 9.4 environment variable feature.

However, when running next locally, then they do have access to the environment variables.

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

See minimal reproduction sample: https://github.com/TheHolyWaffle/env-test

  1. Create .env file with “TEST=Hello World”
  2. Create an api route that echoes that env variable
  3. Deploy to Vercel

Expected behavior

The deployment on Vercel should have the same .env behaviour as when running nextjs locally using next dev.

System information

  • Next.js 9.4.2

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
TheHolyWafflecommented, May 27, 2020

Can confirm that 9.4.3-canary.1 seems to have fixed the issue: https://env-test-three.now.sh/api/print

1reaction
denispixicommented, May 29, 2020

@denispixi yes you should update to the latest stable version of Next.js (v9.4.4) to resolve this

I’ll try. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Environment Variables
Environment Variables are key-value pairs configured outside your source code so that each value can change depending on the Environment.
Read more >
Issue #10795 · vercel/next.js - Environment Variables Locally
Add a .env.build file in the root of your project. Add a simple variables like: ABC=test; Try to access this variable on your...
Read more >
Environments and Stages - Next Right Now
It can be either “development” (localhost) or “production” (on Vercel's servers). The environment is defined by the NODE_ENV environment variable.
Read more >
How to properly set environment variables in Next.js app ...
Simply creating a .env.local (or .env ) file with your environment variables should be enough to be picked by Next.js on the server....
Read more >
Env Variables and Modes
For Vue templates or other HTML that gets compiled into JavaScript strings, ... Vite uses dotenv to load additional environment variables from the...
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