NodeJS Firebase错误:无法从.env加载环境变量

l7wslrjt  于 2023-04-20  发布在  Node.js
关注(0)|答案(1)|浏览(262)

我正在使用Firebase为我的应用程序运行后端。当我尝试使用firebase emulators:start --inspect-functions运行后端时,它说
节点v:18.13.0
Firebase-tools v:^11.18.0
Firebase函数v:^4.2.0

i  emulators: Starting emulators: auth, functions, storage
⚠  functions: You are running the Functions emulator in debug mode (port=9229). This means that functions will execute in sequence rather than in parallel.
⚠  functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: firestore, database, hosting, pubsub
⚠  functions: Unable to fetch project Admin SDK configuration, Admin SDK behavior in Cloud Functions emulator may be incorrect.
i  ui: Emulator UI logging to ui-debug.log
i  functions: Watching "/home/ktk/code/js/sol/functions/functions" for Cloud Functions...
⚠  functions: package.json indicates an outdated version of firebase-functions. Please upgrade using npm install --save firebase-functions@latest in your functions directory.
✔  functions: Using node@18 from host.
⬢  functions: Failed to load function definition from source: FirebaseError: Failed to load environment variables from .env.

我检查过的东西:

  • .env确实存在
  • env语法正确
  • 执行chmod 777 .env以更改权限
oipij1gg

oipij1gg1#

这可能是由于任何原因:
仔细检查文件是否包含以下行:

FIREBASE_API_KEY=XYZ123 
FIREBASE_AUTH_DOMAIN=mydomain.firebaseapp.com 
FIREBASE_DATABASE_URL=https://mydatabase.firebaseio.com 
etc...

检查.env文件是否在gitignore.npmignore中被索引。如果忽略该文件,将不会加载环境变量。设置变量时,请确保=周围没有空格。

相关问题