I know some people have complained about this in the past but I can't seem to get this working.
node: v10.15.0
firebase-functions: ^3.0.0
firebase-tools:
firebase: 7.3.2
firebase-admin: ^8.0.0
running firebase serve fails to read functions.config()
I've tried:
Running firebase serve should read functions.config()
functions.config() seems to always be empty
This is the location that the code should read functions.config() values
TypeError: Cannot read property 'secret' of undefined
at Object.
at Module._compile (internal/modules/cjs/loader.js:689:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Module.require (internal/modules/cjs/loader.js:637:17)
at require (internal/modules/cjs/helpers.js:22:18)
at Object.
at Module._compile (internal/modules/cjs/loader.js:689:30)
No... running firebase deploy --only functions gives me the exact same error.
If I replace functions.config().myValue with the actual value, both firebase serve and firebase deploy work - but this isn't the intended behavior... I don't want my secret key value exposed in the code

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
Same here !
after few search, the issue is related here with a hack to fix ;)
https://github.com/firebase/firebase-functions/issues/264#issuecomment-398574364
@Lucas-Geitner, I tried that approach (mentioned by @laurenzlong) and called it out in my initial comment, but the solution did not solve the problem.
Are you sure you need to use the serve method and not the shell command ?
@Lucas-Geitner I think you don't use environments in your firebase project.
We use it all the time in cloud projects, that's why we need to put the envs in a place.
You can see that's the way Firebase had implemented that:
I'm going to explain it with a short code as a scenario using the @super-jb issue.
I have the same issue implementing my firebase functions project, and it's not possible to get any envs by code, but it's totally possible using the console:
const config = {
all: {
env: process.env.NODE_ENV || firebaseEnv || 'development',
root: path.join(__dirname, '..'),
port: process.env.PORT || 9000,
ip: process.env.IP || '0.0.0.0',
defaultEmail: getFirebaseValue('emails.default'),
sendgridKey: getFirebaseValue('sendgrid.key') || 'sendgridKey',
masterKey: getFirebaseValue('master.key') || 'masterKey',
jwtSecret: getFirebaseValue('jwt.secret') || 'jwtSecret',
watsonKey: getFirebaseValue('watson.key'),
facebook: {
fbAppId: getFirebaseValue('facebook.app-id'),
fbAppSecret: getFirebaseValue('facebook.app-secret'),
authCallbackUrl: getFirebaseValue('facebook.auth-callback'),
},
unsplash: {
applicationId: getFirebaseValue('unsplash.app-key'),
secret: getFirebaseValue('unsplash.app-secret'),
callbackUrl: getFirebaseValue('unsplash.callback-url'),
},
AWS: {
accessKeyId: getFirebaseValue('aws.access-key'),
secrectAccessKey: getFirebaseValue('aws.secret-access-key'),
region: getFirebaseValue('aws.region'),
bucket: getFirebaseValue('aws.bucket'),
},
The method getFirebaseValue() is below:
import _ from 'lodash';
const functions = require('firebase-functions');
const functionsEnvs = functions.config();
export const firebaseEnv = process.env.FIREBASE_CONFIG
? 'production'
: 'development';
export const getFirebaseValue = envKey => {
console.log(`[DEBUG] get the env ${envKey}: `, _.get(functionsEnvs, envKey));
return _.has(functionsEnvs, envKey)
? _.get(functionsEnvs, envKey)
: undefined;
};
The answers I got here is below:
functions[webApi]: http function initialized (http://localhost:5000/social-api/us-central1/webApi).
i functions: Beginning execution of "webApi"
> [DEBUG] get the env emails.default: undefined
> [DEBUG] get the env sendgrid.key: undefined
> [DEBUG] get the env master.key: undefined
> [DEBUG] get the env jwt.secret: undefined
> [DEBUG] get the env watson.key: undefined
> [DEBUG] get the env facebook.app-id: undefined
> [DEBUG] get the env facebook.app-secret: undefined
> [DEBUG] get the env facebook.auth-callback: undefined
> [DEBUG] get the env unsplash.app-key: undefined
> [DEBUG] get the env unsplash.app-secret: undefined
We can follow the instructions that @Lucas-Geitner mentioned above.
https://github.com/firebase/firebase-functions/issues/264#issuecomment-398574364
Since this is an issue with firebase serve I am going to move this over to the firebase-tools repository.
In my case firebase functions:config:get | ac .runtimeconfig.json does generate a .runtimeconfig.json filled with all properties but still, the serve doesn't load them.
This only happens in Windows 10.
Edit: looks like the first time I used firebase functions:config:get > .runtimeconfig.json and the invisible characters remained there even though I later used the ac command. Solution was to remove the file and create it again.
Hmmm yeah I am seeing this too but interestingly I can fix it like this:
$ CLOUD_RUNTIME_CONFIG=$(pwd)/functions/.runtimeconfig.json firebase emulators:start
So I think there may be something going wrong in firebase-functions, but I will keep investigating.
@samtstern adding the CLOUD_RUNTIME_CONFIG fixed the issue for me. Nothing else worked, no matter where I put the .runtimeconfig.json
I am on Windows 10 and I cannot make .runtimeconfig.json used nor by the functions emulator, nor by firebase serve.
Just ran into the same issue. It looks like it was introduced in firebase-functions @ 3.4.0. I confirmed it is working properly in 3.3.0. Related: https://github.com/firebase/firebase-functions/issues/264
@mariotacke can you file a new issue in the firebase-functions repo with detailed information about the versions of firebase-tools and firebase-functions you're using (in addition to the node version specified in your package.json) and specific debug logs and output? I'm not able to reproduce.
The fix has been released in 7.16.0
I have 7.16.1 and I still have the problem on MacOS.
firebase serve --only functions ----> gives undefined value in local
firebase deploy --only functions ----> works in prod
This is still happening to me
(base) Liezls-MacBook-Pro:functions lie$ node --version
v12.13.1
(base) Liezls-MacBook-Pro:functions lie$ firebase --version
8.6.0
const CONFIG = functions.config();
const CONFIG = functions.config();
console.log("config");
console.log(JSON.stringify(CONFIG));
// console.log(Object.keys(functions))
const nextjsUrl = CONFIG.nextjs.url;
TypeError: Cannot read property 'url' of undefined
cc @samtstern Still can't make this work. Could we re-open this issue for debugging?
@liezl200 @LeoLetourneur if this is happening to you please open a new issue, this works in our testing so you're likely running into something new.
Make sure you have a .runtimeconfig.json file inside your functions folder!
I'm also running into a similar issue where functions.config() always returns an empty object.
Environment:
Windows 10
node 12.16.3
firebase-functions 3.11.0
firebase-tools 8.14.1
relevant parts of package.json:
{
"scripts":{
"build": "rm -rf ./dist && tsc --outDir dist && cp package.json yarn.lock ./dist",
"serve": "yarn build && firebase emulators:start --only functions,firestore",
...
}
}
UPDATE:
We're using yarn, not npm in our project and after some additional digging I've found this:
When I run yarn serve the config is always empty.
When I run npm run serve the config is not empty and things work as they should, so it must have something to do with the way yarn is running the command vs npm.
Most helpful comment
I have 7.16.1 and I still have the problem on MacOS.
firebase serve --only functions ----> gives undefined value in local
firebase deploy --only functions ----> works in prod