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
Step 1:
First run the command: npm install --save-dev env-cmd@10.1.0
Step 2:
Replace env-cmd .env-development gatsby develop
with ./node_modules/.bin/env-cmd -f ./.env.development gatsby develop
Thanks, everyone. This solves it for me
"develop": "env-cmd --file .env.development --fallback gatsby develop",
and pass in this value .env.development file GATSBY_GRAPHQL_IDE=playground
.
In case, you want to understand how to set it up better, You can check out this article on CSS Tricks by Adebiyi Adedotun
use the -f flag and make sure the path to your .env.development file is correct.
"develop": "env-cmd -f ./.env.development gatsby develop"
Ran into the same issue, here's a snippet of gatsby-config.js I added to make the ".env.development" file visible to gatsby. (Not sure if this is the only way, node/Gatsby experts please chime in)
let activeEnv =
process.env.GATSBY_ACTIVE_ENV || process.env.NODE_ENV || "development"
console.log('Using environment config: ${activeEnv}')
require("dotenv").config({
path: `.env.${process.env.NODE_ENV}`,
})
Based on this gatsby-config.js, here is the develop script in package.json (unchanged) -
...
"develop": "gatsby develop",
...
Finally, starting the gatsby app using
npm run develop
, the logs mentions playground being available -
You can now view gatsby-starter-hello-world in the
⠀
http://localhost:8000/
⠀
View the GraphQL Playground, an in-browser IDE, to
⠀
http://localhost:8000/___graphql
Adding the let snippet to the gatsby-config.js file did the trick for me! And then starting up with gatsby develop Tnx! Great help!
This has been updated in the latest version of env-cmd, if you are using version <9.0.0 then it will work perfectly but with version >9.0.0 the default environment file it will look for is .env
use env-cmd -f .env.development gatsby develop
instead, here -f is provided for custom file name.