Skip to content

firebase serve fails with TypeError on Travis CI #364

Closed

Description

@sbekrin

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
  • I also have sudo: required in Travis config
  • Everything works fine with same setup locally

Versions:

Any ideas?

Activity

  1. laurenzlong commented on Jun 9, 2017

    @laurenzlong
    Contributor

    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.

  2. sbekrin commented on Jun 10, 2017

    @sbekrin
    Author

    @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.

  3. laurenzlong commented on Jun 12, 2017

    @laurenzlong
    Contributor

    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?

  4. sbekrin commented on Jun 12, 2017

    @sbekrin
    Author

    @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)
  5. sbekrin commented on Jun 16, 2017

    @sbekrin
    Author

    @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?

  6. laurenzlong commented on Jun 20, 2017

    @laurenzlong
    Contributor

    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?

  7. sbekrin commented on Jun 20, 2017

    @sbekrin
    Author

    @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.
  8. laurenzlong commented on Jun 20, 2017

    @laurenzlong
    Contributor

    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.

  9. laurenzlong commented on Jun 20, 2017

    @laurenzlong
    Contributor

    Actually I'll leave the issue open in case anybody else wants to jump in.

  10. sbekrin commented on Jun 20, 2017

    @sbekrin
    Author

    @laurenzlong thanks, this is definitely pretty weird issue. I'll update this discussion if I came up with something.

  11. Tivoli commented on Aug 19, 2017

    @Tivoli

    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.
    
  12. 4 remaining items

  13. maxinteger commented on Oct 23, 2017

    @maxinteger

    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 === undefined and refreshToken equal with the --token parameter)

    So when ensureDefaultCredentials read the tokens from the configstore it return with undefined

  14. kossnocorp commented on Mar 24, 2018

    @kossnocorp
    Contributor

    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 deploy command as an example as there it uses completely different authentication approach. Could you help me with the direction?

  15. shaunpersad commented on Apr 3, 2018

    @shaunpersad

    having the same problem :(

  16. laurenzlong commented on Apr 3, 2018

    @laurenzlong
    Contributor

    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.

  17. shaunpersad commented on Apr 3, 2018

    @shaunpersad

    @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.

  18. Shyam-Chen commented on Apr 13, 2018

    @Shyam-Chen
    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: 2
    Command: sh
    Arguments: -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.
  19. Shyam-Chen commented on Apr 13, 2018

    @Shyam-Chen

    hosting is working for me.

    $ yarn firebase serve --only hosting -p 8000 --token $FIREBASE_TOKEN

      "scripts": {
        // ...
        "firebase": "firebase",
        // ...
      },
    $ yarn firebase serve --only functions --port 5000 --token $FIREBASE_TOKEN
    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.
  20. added a commit that references this issue on Jun 29, 2018
  21. codyzu commented on Jul 10, 2018

    @codyzu

    @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!

  22. laurenzlong commented on Jul 18, 2018

    @laurenzlong
    Contributor

    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.

  23. lukepighetti commented on Oct 5, 2018

    @lukepighetti

    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-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\"."}

    Is this related? kubernetes/kubernetes#8512

  24. laurenzlong commented on Oct 5, 2018

    @laurenzlong
    Contributor

    @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

  25. lukepighetti commented on Oct 6, 2018

    @lukepighetti

    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!

  26. laurenzlong commented on Oct 9, 2018

    @laurenzlong
    Contributor

    Thanks for the update!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions