skip to Main Content

According to the Firebase documentation, Loaded environment variables from .env. should be printed to the console when deploying functions. My functions are exported inside src/functions/functions.ts. This is specified in my package.json file:
main: lib/src/functions/functions.js (since I am using TypeScript, I have to specify the generated javascript file inside lib).

I have tried to locate the .env files inside the root directory, and inside the src/functions/ folder. None of them works. Does anyone have any ideas?

3

Answers


  1. I had the same issue, turns out the firebase-tools version installed globally which where used for deploy where not updated by npm install -g firebase-tools.

    Solution:

    1. Confirm the firebase-tools versions: firebase --version which should be more than 11
    2. Check where is the binary: which firebase
    3. If it’s in /usr/local/bin/firebase run sudo rm -rf /usr/local/bin/firebase
    4. If it’s in some node-related folder, try to npm uninstall -g firebase-tools
    5. Reinstall: npm install -g firebase-tools
    6. Confirm location and version: firebase --version. As of 1st Oct 2022: 11.13.0
    Login or Signup to reply.
  2. i had the same problem. I was able to solve it by moving the .env files to the base of the project.

    Example:

    • functions/.env.
    • functions/.env.qa
    • functions/.env.dev
    • functions/.env.etc

    Hope it helps you
    structure

    Login or Signup to reply.
    1. Try to move your .env file to your root directory.
    2. In the file you need your environment variable, run this
    import dotenv from "dotenv"; (ES Modules)
    

    or

    const dotenv = require('dotenv); ( CommonJs )
    

    then

    dotenv.config({ path: {PATH to your .env file})
    

    In case you don’t know how to get the path: right-click your .env file in vscode => choose Copy Path

    Your environment should work properly

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search