When using vercel env pull it places an env file in the .vercel folder. For example vercel env pull --environment=production will create .vercel/env.production.local.
I would like to run the next dev server or local production build so that it uses those env variables, but when running next dev or next start it seems to only pick up env files from the repository root.
How can I make those commands pick up the pulled files from the .vercel directory? Or where these env files not meant to be used like that?
When using vercel env pull with the --environment flag, it creates an .env.production.local file in the .vercel folder like you said. But by default, Next.js doesn't automatically get environment variables from that folder. To make Next.js pick up environment variables from the .vercel folder, you need to configure it to do so:
npm install dotenv --save-dev.Use the following code in your next.config.js file:
const path = require('path');
require('dotenv').config({ path: path.resolve(process.cwd(),'.vercel/env.production.local') });
You can then add your configurations in module.exports.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With