dotenv file is not loading environment variables

后端 未结 9 1491
别那么骄傲
别那么骄傲 2020-12-13 08:36

I have .env file at root folder file

NODE_ENV=development
NODE_HOST=localhost
NODE_PORT=4000
NODE_HTTPS=false
DB_HOST=localhost
DB_USERNAME=user
DB         


        
相关标签:
9条回答
  • 2020-12-13 09:31

    I've had this problem and it turned out that REACT only loads variables prefixed with REACT_APP_

    VueJs can have a similar issue as it expects variables to be prefixed with: VUE_APP_

    0 讨论(0)
  • 2020-12-13 09:33

    In my case .env was read fine, but not .env.local.

    Updating package.json to name .env into .env.local ( cp ./.env.local .env) solved the problem:

      "myscript": "cp ./.env.local .env && node ./scripts/myscript.js"
    
    0 讨论(0)
  • 2020-12-13 09:36

    In the remote case that you arrive till this point, my issue was quite dumber: I wrongly named my env variables with colon ":" instead of equals "=". Rookie mistake but the resulting behavior was not loading the misspelled variables assignment.

    # dotenv sample content
    
    # correct assignment
    USER=sample@gmail.com
    
    # wrong assignment (will not load env var)
    USER : sample@gmail.com
    
    0 讨论(0)
提交回复
热议问题