I have a file name .env.development in the root folder. I had install env-cmd as dev dependencies
when I start the server
> npm run develop
You can set environment variable using your own custom .env
files with -f
flag with env-cmd
. Use this command to set env
variables that are defined in custom file './config/myvar.env'
.
env-cmd -f ./config/myvar.env
For more information use this link
Add -f
to your package.json
file
"develop": "env-cmd -f .env.development gatsby develop",
In Windows.
First create file .env.development
Then add in package.json:
"develop": "env-cmd -f .env.development --fallback gatsby develop"
and: npm run develop
attached: https://css-tricks.com/using-graphql-playground-with-gatsby
I had same problem,
i tried below code
env-cmd -f ./config/myvar.env
its not working for me.
Instead i add full path of config folder like below and its works like charm..!!!!
env-cmd -f fullPath/config/myvar.env
You can rename .env.development
to just .env
and then run env-cmd gatsby develop
, this will look for environment variables inside .env
file.
You can also update the develop
node script inside the package.json
like the following:
"develop": "env-cmd gatsby develop"
Then you can run the node script,
npm run develop
or
gatsby develop
In my case got this error :
Error: Failed to find .env file at path: .env.local at getEnvFile (E:\project\....)
Then i just rename .env.development
file to .env.local
and it is working fine.
or if you are working on remote git repository then check you have pulled latest changes made by your team member to your local dev environment.