.env variables behave different between local and Vercel
See original GitHub issueBug 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
- Create .env file with “TEST=Hello World”
- Create an api route that echoes that env variable
- Deploy to Vercel
Expected behavior
The deployment on Vercel should have the same .env behaviour as when running nextjs locally using next dev
.
- Local: the api route correctly echoes “Hello World”.
- Vercel: the api route returns an internal server error. (Try https://env-test.theholywaffle.now.sh/api/print)
System information
- Next.js 9.4.2
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Can confirm that 9.4.3-canary.1 seems to have fixed the issue: https://env-test-three.now.sh/api/print
I’ll try. Thanks!