You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
firebase serve fails with TypeError on Travis CI #364
Hey there! I'm trying to run firebase serve on Travis CI to run smoke tests. App fails to start with Error: An unexpected error has occurred.:
i functions: Preparing to emulate HTTPS functions. Support for other event types coming soon.
[2017-06-05T12:44:01.457Z] TypeError: Cannot read property 'refresh_token' of undefined
I'm using firebase serve --debug --only functions,hosting --token $FIREBASE_TOKEN --project $FIREBASE_PROJECT to run it
@laurenzlong thanks for support! How can I make sure my exported json file is picked up correctly? As for now I don't see any changes and firebase serve fails with same error.
Can you ensure that you've given the absolute path to the GOOGLE_APPLICATION_CREDENTIALS environment variable? Can you also try printing out process.env.GOOGLE_APPLICATION_CREDENTIALS to ensure that the environment variable has been set properly?
@laurenzlong yep, everything looks good. GOOGLE_APPLICATION_CREDENTIALS path is absolute, file is readable.
Few more things:
firebase fails to start before my app, that means functions/index.js is not even initialized
I don't see it in debug output to make requests to specified endpoints in service *.json, they are still different (not sure if this is actually a problem)
@laurenzlong I've tried to debug token auth flow logic with no luck. Only thing I can assume is that it trying to read refresh_token from config before setting it. Do you have any other ideas what might be the problem?
Hey @sergeybekrin, are you making any API requests within your functions? As well, can you try again but remove the "--token $FIREBASE_TOKEN" flag? And do you see the same error if you run firebase serve with just hosting and not functions?
@laurenzlong behaviour is changed after I updated deps and used FIREBASE_TOKEN instead of --token, at least I don't see TypeError anymore:
I'm using functions.config().firebase and firebase.initializeApp(config), no other direct API calls.
firebase serve --only hosting works perfectly fine.
firebase serve --only functions,hosting does't not fail anymore, but hangs after ✔ hosting: Local server: http://localhost:5000 message — it should run functions after that I believe.
firebase serve --only functions fails with Error: No targets found. Valid targets are: functions,hosting only on Travis.
Having the same issue trying to use firebase serve --only functions --debug inside of a docker container for local development and testing, the initial HTTP calls for the token do respond with 200s.
functions_1 | i functions: Preparing to emulate HTTPS functions. Support for other event types coming soon.
functions_1 | [2017-08-18T08:26:51.746Z] TypeError: Cannot read property 'refresh_token' of undefined
functions_1 | at module.exports (/usr/local/share/.config/yarn/global/node_modules/firebase-tools/lib/ensureDefaultCredentials.js:31:45)
functions_1 | at Object._startEmulator [as start] (/usr/local/share/.config/yarn/global/node_modules/firebase-tools/lib/serve/functions.js:91:3)
functions_1 | at /usr/local/share/.config/yarn/global/node_modules/firebase-tools/lib/serve/index.js:16:19
functions_1 | at arrayMap (/usr/local/share/.config/yarn/global/node_modules/lodash/lodash.js:660:23)
functions_1 | at Function.map (/usr/local/share/.config/yarn/global/node_modules/lodash/lodash.js:9571:14)
functions_1 | at _serve (/usr/local/share/.config/yarn/global/node_modules/firebase-tools/lib/serve/index.js:14:21)
functions_1 | at Command._action (/usr/local/share/.config/yarn/global/node_modules/firebase-tools/commands/serve.js:42:12)
functions_1 | at /usr/local/share/.config/yarn/global/node_modules/firebase-tools/lib/command.js:176:29
functions_1 | at tryCatch (/usr/local/share/.config/yarn/global/node_modules/rsvp/dist/rsvp.js:525:12)
functions_1 | at invokeCallback (/usr/local/share/.config/yarn/global/node_modules/rsvp/dist/rsvp.js:538:13)
functions_1 |
functions_1 | Error: An unexpected error has occurred.
functions_1 | error Command failed with exit code 2.
Any news about this issue? It prevents us from running integration tests for Firebase Functions on CI which is very frustrating!
I would be glad to help with PR, but I can't figure out how to properly pass the token to the auth module. I can't use deploy command as an example as there it uses completely different authentication approach. Could you help me with the direction?
Hey everyone, we just released firebase-functions-test, a testing SDK specifically for writing unit tests. That would be better suited for CI systems than using firebase serve. Check it out (repo, doc), and let me know if this doesn't suit your use case for some reason.
@laurenzlong My particular use case is to simply run firebase serve inside a docker container in general, not necessarily in a CI context. As a few others have mentioned in this thread, having a FIREBASE_TOKEN env variable in the container does not work.
yarn run v1.5.1
$ firebase serve --only functions -p 5000 --token <FIREBASE_TOKEN>
=== Serving from '/<DIRECTORY_NAME>'...
i functions: Preparing to emulate functions.
Error: An unexpected error has occurred.
error An unexpected error occurred: "Command failed.Exit code: 2Command: shArguments: -c firebase serve --only functions -p 5000 --token <FIREBASE_TOKEN>Directory: /<DIRECTORY_NAME>Output:".
info If you think this is a bug, please open a bug report with the information provided in"/<DIRECTORY_NAME>/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
yarn run v1.6.0
$ firebase serve --only functions --port 5000 --token $FIREBASE_TOKEN
=== Serving from '/Vue-Fullstack-Starter'...
i functions: Preparing to emulate functions.
Warning: You're using Node.js v8.11.3 but Google Cloud Functions only supports v6.11.5.error: /Vue-Fullstack-Starter/node_modules/firebase-admin/lib/auth/credential.js:94 throw new error_1.FirebaseAppError(error_1.AppErrorCodes.INVALID_CREDENTIAL, 'Failed to parse refresh token file: ' + error); ^Error: Failed to parse refresh token file: Error: Refresh token must contain a "refresh_token" property.
@laurenzlong I am working on an integration test for callable HTTPS function. AFAIK, the firebase-functions-test module is not (yet) compatible with callable https functions. Can you confirm?
For that reason, I too am running the functions emulator inside a dockerized environment in our CI/CD pipeline. Updating to the latest release made it work, but I'm wondering if this is generally a bad idea?
Hey @codyzu, yes support for callable functions in firebase-functions-test is coming, thanks for your patience. Running the emulator in a dockerized environment isn't generally a bad idea. The only trade off is that it's slower than running unit tests written with firebase-functions-test.
Basically no matter what I do, firebase-admin write/read tests work on my dev machine, but when it's in a CI/CD container (tested Codeship and Bitbucket Pipelines) I get this error, which repeats until the Jest runner times out.
[2018-10-05T12:53:51.316Z] @firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Failed to parse access token response: Error: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80. Error code: ENOTFOUND\"."}
Activity
laurenzlong commentedon Jun 9, 2017
Hey @sergeybekrin thanks for the report! This is definitely an edge case that we overlooked.
In the meanwhile, here's a workaround.
Please reopen if this doesn't work.
sbekrin commentedon Jun 10, 2017
@laurenzlong thanks for support! How can I make sure my exported json file is picked up correctly? As for now I don't see any changes and
firebase servefails with same error.laurenzlong commentedon Jun 12, 2017
Can you ensure that you've given the absolute path to the GOOGLE_APPLICATION_CREDENTIALS environment variable? Can you also try printing out process.env.GOOGLE_APPLICATION_CREDENTIALS to ensure that the environment variable has been set properly?
sbekrin commentedon Jun 12, 2017
@laurenzlong yep, everything looks good.
GOOGLE_APPLICATION_CREDENTIALSpath is absolute, file is readable.Few more things:
functions/index.jsis not even initializedsbekrin commentedon Jun 16, 2017
@laurenzlong I've tried to debug token auth flow logic with no luck. Only thing I can assume is that it trying to read
refresh_tokenfrom config before setting it. Do you have any other ideas what might be the problem?laurenzlong commentedon Jun 20, 2017
Hey @sergeybekrin, are you making any API requests within your functions? As well, can you try again but remove the "--token $FIREBASE_TOKEN" flag? And do you see the same error if you run firebase serve with just hosting and not functions?
sbekrin commentedon Jun 20, 2017
@laurenzlong behaviour is changed after I updated deps and used
FIREBASE_TOKENinstead of--token, at least I don't see TypeError anymore:functions.config().firebaseandfirebase.initializeApp(config), no other direct API calls.firebase serve --only hostingworks perfectly fine.firebase serve --only functions,hostingdoes't not fail anymore, but hangs after✔ hosting: Local server: http://localhost:5000message — it should run functions after that I believe.firebase serve --only functionsfails withError: No targets found. Valid targets are: functions,hostingonly on Travis.laurenzlong commentedon Jun 20, 2017
Hey @sergeybekrin the behavior is extremely bizarre and I'm out of ideas. Could you try writing unit tests instead of using firebase serve inside Travis? Here's a guide on how to do it: https://firebase.google.com/docs/functions/unit-testing
Please do let me know if you do end up figuring this out. I'd be very curious about what works.
Sorry I can't be more helpful! You can also try posting a question to Stack Overflow and see if anybody else has figured it out.
laurenzlong commentedon Jun 20, 2017
Actually I'll leave the issue open in case anybody else wants to jump in.
sbekrin commentedon Jun 20, 2017
@laurenzlong thanks, this is definitely pretty weird issue. I'll update this discussion if I came up with something.
Tivoli commentedon Aug 19, 2017
Having the same issue trying to use
firebase serve --only functions --debuginside of a docker container for local development and testing, the initial HTTP calls for the token do respond with 200s.4 remaining items
maxinteger commentedon Oct 23, 2017
Hi. I get the same error when I tried to run serve functions in a docker image.
Looks like the problem is the empty configstore. The auth does not set the token from the cli parameters because this line never executed:
https://github.com/firebase/firebase-tools/blob/master/lib/auth.js#L230
(the
currentRefreshToken === undefinedandrefreshTokenequal with the--tokenparameter)So when
ensureDefaultCredentialsread thetokensfrom the configstore it return withundefinedkossnocorp commentedon Mar 24, 2018
Hey, @laurenzlong!
Any news about this issue? It prevents us from running integration tests for Firebase Functions on CI which is very frustrating!
I would be glad to help with PR, but I can't figure out how to properly pass the token to the auth module. I can't use
deploycommand as an example as there it uses completely different authentication approach. Could you help me with the direction?shaunpersad commentedon Apr 3, 2018
having the same problem :(
laurenzlong commentedon Apr 3, 2018
Hey everyone, we just released firebase-functions-test, a testing SDK specifically for writing unit tests. That would be better suited for CI systems than using firebase serve. Check it out (repo, doc), and let me know if this doesn't suit your use case for some reason.
shaunpersad commentedon Apr 3, 2018
@laurenzlong My particular use case is to simply run
firebase serveinside a docker container in general, not necessarily in a CI context. As a few others have mentioned in this thread, having a FIREBASE_TOKEN env variable in the container does not work.Shyam-Chen commentedon Apr 13, 2018
Shyam-Chen commentedon Apr 13, 2018
hostingis working for me.$ yarn firebase serve --only hosting -p 8000 --token $FIREBASE_TOKEN$ yarn firebase serve --only functions --port 5000 --token $FIREBASE_TOKENFixes issue firebase#364
codyzu commentedon Jul 10, 2018
@laurenzlong I am working on an integration test for callable HTTPS function. AFAIK, the firebase-functions-test module is not (yet) compatible with callable https functions. Can you confirm?
For that reason, I too am running the functions emulator inside a dockerized environment in our CI/CD pipeline. Updating to the latest release made it work, but I'm wondering if this is generally a bad idea?
Thanks for your time!
laurenzlong commentedon Jul 18, 2018
Hey @codyzu, yes support for callable functions in firebase-functions-test is coming, thanks for your patience. Running the emulator in a dockerized environment isn't generally a bad idea. The only trade off is that it's slower than running unit tests written with firebase-functions-test.
lukepighetti commentedon Oct 5, 2018
Hello, I do not know if this is related but I am unable to get
firebase-admin(Node.js) to communicate when inside a CI/CD docker container.https://stackoverflow.com/questions/52655375/how-do-i-put-firebase-admin-credentials-in-an-environment-variable
Basically no matter what I do,
firebase-adminwrite/read tests work on my dev machine, but when it's in a CI/CD container (tested Codeship and Bitbucket Pipelines) I get this error, which repeats until the Jest runner times out.[2018-10-05T12:53:51.316Z] @firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"Failed to parse access token response: Error: Error while making request: getaddrinfo ENOTFOUND metadata.google.internal metadata.google.internal:80. Error code: ENOTFOUND\"."}Is this related? kubernetes/kubernetes#8512
laurenzlong commentedon Oct 5, 2018
@lukepighetti I'm not an expert on firebase-admin, I suggest looking through the issues in that Github repo, and filing a new one if it doesn't exist yet: https://github.com/firebase/firebase-admin-node
lukepighetti commentedon Oct 6, 2018
Hi Lauren, forgot to follow up. I found the solution to my problem, it was a typo when initializing admin. Thanks for the quick reply!
laurenzlong commentedon Oct 9, 2018
Thanks for the update!