vercel nextjs not load env variables - next.js

When I do git push to the project without put .env to .gitignore file the project work fine and load the env variables but when put .env in .gitignore file and do git push and add env variables to project setting and redeploy the project in this case vercel not load env variables.
UI Setting env variables
I don't know why ?
any suggestions please !

Related

How to set environment variables with Prisma, Nextjs, and Vercel

Nextjs wants you to use a .env.local file to store env vars.
Prisma uses .env
If I use a .env.local file then setting up the Prisma db
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}
I get a DATABASE_URL does not exist error.
What's the right way to set up env vars for a Prisma, Nextjs, Vercel app?
You can use dotenv-cli to force loading specific environment file.
1- Install dotenv-cli package
2- create script to run env before prisma migration on your package
"scripts": {
...
"prismaDev": "dotenv -e .env.local prisma migrate dev ",
}
3- now you can simply run npm run prismaDev
You can load environment variables with process.env.DATABASE_URL in your case and you can leave it in .env as Prisma asks for. Nextjs can handle multiple .env files without any extra effort.
No need to use an extra package, Nextjs will handle the env vars for you.
https://nextjs.org/docs/basic-features/environment-variables
You can leave the standard setup and use the created .env file (by the prisma cli:
https://www.prisma.io/docs/getting-started/setup-prisma) and add your connection string.
the rest is magically handled by next.
Be sure to follow the instructions (manual or cli pointers) regarding gitignore and such..
To reiterate: both can live next to each other! Check the next documentation for load order if it matters. (see link above)

Vue firebase hosting environment variables

Currently in my dev environment i have my .env.development file with my firebase environment variables stored as:
VUE_APP_FB_API_KEY='abc123000123',
VUE_APP_FB_AUTH_DOMAIN='site.firebaseapp.com',
etc...
This works fine for my dev machine but once i deploy this to firebase hosting it breaks and throws console errors that the various options are not configured. I tried adding them with
firebase functions:config:set env.VUE_APP_FB_API_KEY='abc123000123'
but this is still not working for me.
What is wrong here? Also per the docs upper-case characters are not allowed..
When you run on local, vue-cli will read .env.development config file. But when you build for production, it will use production mode and will read .env file.
You should copy .env.development to .env then build and deploy again.
Or you can create .env.production file, which is only used for production build.
.env # loaded in all cases
.env.local # loaded in all cases, ignored by git
.env.[mode] # only loaded in specified mode
.env.[mode].local # only loaded in specified mode, ignored by git
You can read more about the enviroment variable and build mode in vue-cli official document.

composer rewrites my .env file by new generated one

When I run composer install for my symfony project, my .env file is rewrote by new generated one. What should I do to save my .env intact?
Applications created after November 2018 had a slightly different system, read changes
From the official documentation
.env.local : defines/overrides env vars for all environments but only in your local machine
.env : defines the default value of env vars.
The .env and .env.<environment> files should be committed to the shared repository because they are the same for all developers. However, the .env.local and .env.<environment>.local and files should not be committed because only you will use them. In fact, the .gitignore file that comes with Symfony prevents them from being committed.

Environment variables not found in console and composer

I set environment variables and removed parameters.yml file according to new recommended configuration.
In my local environment (WAMP), I set these in .htaccess file in the root of my project. The app is working, but Symfony console and composer can't find variables. I can't find why. Do you have an idea ?
I think you have to set environment variables on the terminal. PHP CLI mode will not load instruction within .htaccess
export VARNAME="my value"
in your case with windows in cmd it will be:
set NEWVAR=SOMETHING

How can I run a meteor app and have it use the mup.json and settings.json file inside the staging folder?

When I run an app with
meteor --settings staging/settings.json
it does not use the mongo database that is on staging/mup.json file
I have the following files in the staging folder:
mup.json
mupc.json
settings.json
Online I have read that the filename usually is mup.js but on the rep I have mup.son
How can I run the app with the database that is on the staging/mup.json file ?
I believe that the mup.json file is used to set the environment vars on the deploy server. It's not meant for running your app locally. In order to run the app locally and connect it to Mongo, you'll need to set the env var.
// Mac or Linux
$ export MONGO_URL=mongodb://yourMongoURI
// Windows
$ set MONGO_URL=mongodb://yourMongoURI

Resources