env-cmd error failed to locate ./.env file in gatsby?

后端 未结 12 676
鱼传尺愫
鱼传尺愫 2020-12-15 05:33

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
         


        
相关标签:
12条回答
  • 2020-12-15 05:50

    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

    0 讨论(0)
  • 2020-12-15 05:51

    Add -f to your package.json file

    "develop": "env-cmd -f .env.development gatsby develop",
    
    0 讨论(0)
  • 2020-12-15 05:56

    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

    0 讨论(0)
  • 2020-12-15 05:59

    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
    
    0 讨论(0)
  • 2020-12-15 06:06

    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
    
    0 讨论(0)
  • 2020-12-15 06:08

    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.

    0 讨论(0)
提交回复
热议问题