Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

firebase serve doesn't pick up .runtimeconfig.json #711

Closed
MLoughry opened this issue Mar 25, 2018 · 14 comments
Closed

firebase serve doesn't pick up .runtimeconfig.json #711

MLoughry opened this issue Mar 25, 2018 · 14 comments

Comments

@MLoughry
Copy link

MLoughry commented Mar 25, 2018

Version info

3.17.4, 3.17.7

Platform Information

Windows 10 (10.0,6299)
NodeJS v 8.8.0

Steps to reproduce

PS E:\project\functions> firebase functions:config:get > .runtimeconfig.json
PS E:\project\functions> firebase serve --only functions

=== Serving from 'E:\project'...

i  functions: Preparing to emulate functions.
Warning: You're using Node.js v8.8.0 but Google Cloud Functions only supports v6.11.1.
!  functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
!  functions: Error from emulator. FirebaseError: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'private_key' of undefined
    at Object.<anonymous> (E:\project\functions\lib\functions\src\index.js:5:97)
    at Module._compile (module.js:612:30)
    at Object.Module._extensions..js (module.js:623:10)
    at Module.load (module.js:531:32)
    at tryModuleLoad (module.js:494:12)
    at Function.Module._load (module.js:486:3)
    at Module.require (module.js:556:17)
    at require (internal/module.js:11:18)
    at C:\Users\Michael\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:18:11
    at Object.<anonymous> (C:\Users\Michael\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:38:3)

index.ts:

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
const cert = {
    ...functions.config().cert,
    "private_key": functions.config().cert.private_key.replace(/\\n/g, '\n'),
};

admin.initializeApp({
    ...functions.config().firebase,
    credential: admin.credential.cert(cert),
});

Expected behavior

The locally-served functions would pick up the local .runtimeconfig.json file.

Actual behavior

No local (or remote) config is picked up.

@MLoughry
Copy link
Author

Updated the original issue to include that this doesn't work on 3.17.7, either.

PS E:\project\functions> yarn list --pattern firebase*
yarn list v1.5.1
├─ @firebase/[email protected]
├─ @firebase/[email protected]
├─ @firebase/[email protected]
├─ @firebase/[email protected]
├─ @firebase/[email protected]
├─ [email protected]
└─ [email protected]
Done in 0.27s.
PS E:\project\functions> firebase --version
3.17.7

@laurenzlong
Copy link
Contributor

Can you run npm install firebase-functions@latest inside your functions folder and try again?

@MLoughry
Copy link
Author

As listed in my comment above, my functions folder is already on [email protected], which is the latest according to https://github.com/firebase/firebase-functions/releases/tag/v0.9.1

@MLoughry
Copy link
Author

MLoughry commented Apr 1, 2018

I have a minimum repro for this issue: https://github.com/MLoughry/firebase-functions-serve-repro

Hitting the deployed function at https://us-central1-fir-tools-711-repro.cloudfunctions.net/helloWorld:

Hello, world!

Error while trying to serve locally:

=== Serving from 'E:\VSO\firebase-functions-serve-repro'...

i  functions: Preparing to emulate functions.
Warning: You're using Node.js v8.8.0 but Google Cloud Functions only supports v6.11.1.
!  functions: Failed to load functions source code. Ensure that you have the latest SDK by running npm i --save firebase-functions inside the functions directory.
!  functions: Error from emulator. FirebaseError: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'message' of undefined
    at Object.<anonymous> (E:\VSO\firebase-functions-serve-repro\functions\lib\index.js:6:36)
    at Module._compile (module.js:612:30)
    at Object.Module._extensions..js (module.js:623:10)
    at Module.load (module.js:531:32)
    at tryModuleLoad (module.js:494:12)
    at Function.Module._load (module.js:486:3)
    at Module.require (module.js:556:17)
    at require (internal/module.js:11:18)
    at C:\Users\Michael\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:18:11
    at Object.<anonymous> (C:\Users\Michael\AppData\Roaming\npm\node_modules\firebase-tools\lib\triggerParser.js:38:3)

@laurenzlong
Copy link
Contributor

@MLoughry I'm not sure how you created .runtimeconfig.json, but there's weird characters in front of it when you run cat .runtimeconfig.json: (Weird thing is that the question marks are not visible when you open it with a text editor, only when you view it within the terminal)

??{
  "cert": {
    "message": "Hello, world!"
  }
}

You test that this is an issue by launching a node repl:

node
// inside repl:
json = require('.runtimeconfig.json');
// get error: 
SyntaxError: /path/to/.runtimeconfig.json: Unexpected token � in JSON at position 0

Once I replaced your .runtimeconfig.json with another one that contained the same info, but without weird characters, both json = require('.runtimeconfig.json') within a Node shell worked, and firebase serve worked.

@amnrzv
Copy link

amnrzv commented May 8, 2018

I've narrowed down the issue to Windows Powershell.

Running firebase functions:config:get > .runtimeconfig.json in powershell generates a broken json, which when parsed gives Unexpected token � in JSON at position 0.

I've managed to sort it out by running .runtimeconfig.json generation command in Windows command prompt.

Hope this helps.

@denisyilmaz
Copy link

@MLoughry Did you find a solution for your issue? getting the same error message

@laurenzlong
Copy link
Contributor

@denisyilmaz You can use @amnrzv's suggestion, or just opening a text editor and manually creating a .runtimeconfig.json by typing it out may also work if you don't have too many variables. Seems like Windows adds weird characters when you simply run firebase functions:config:get > .runtimeconfig.json

@denisyilmaz
Copy link

I'm on Mac and having same issues as @MLoughry described. I tested the .runtimeconfig.json file if it contains the weird character which it doesn't.

@laurenzlong
Copy link
Contributor

How did you go about testing it? And can you ensure that the file is in the functions folder? (not the project root folder)

@denisyilmaz
Copy link

hah. ok. sorry. moving .runtimeconfig.json solved the problem…

@laurenzlong
Copy link
Contributor

No worries! Glad you figured it out!

@gavanitrate
Copy link

@laurenzlong PowerShell is not outputting incorrect/badly formatted JSON. Instead, by default, PowerShell redirects output as UCS-2 Little Endian encoding. i assume firebase serve expects UTF-8 encoding. there's probably not much that can be done on your end. anyhow firebase functions:config:get | ac .runtimeconfig.json outputs UTF-8 in PowerShell.

@TingAli
Copy link

TingAli commented Mar 21, 2019

I've narrowed down the issue to Windows Powershell.

Running firebase functions:config:get > .runtimeconfig.json in powershell generates a broken json, which when parsed gives Unexpected token � in JSON at position 0.

I've managed to sort it out by running .runtimeconfig.json generation command in Windows command prompt.

Hope this helps.

This solution works to this day. Cheers

joehan added a commit that referenced this issue Apr 13, 2021
* Add publisher to registry file fields (#686)

* Migrate ext:update ref-based flow to include update warnings + min extension version guard (#684)

* Migrate ext:install flow to install via extension reference and remove EAP gating (#679)

* Remove EAP-specific copy in ext:dev:register and ext:dev:publish command (#691)

* Warn user that unpublishing is final in ext:dev:unpublish command (#693)

* Add extMinVersion flag to ext:dev:unpublish command (#698)

* Migrate ext:info flow to retrieve spec from Registry API (#683)

* Migrate "author" terminology to use "publisher" in Extensions CLI commands (#694)

* Fix bug in confirmInstallByReference and refactor ext:install error messages (#702)

* Fix local path detection logic and refactor warnings logic in ext:update flow (#703)

* Migrate extensions warnings relating to audiences to use (backend) launch stage and visibility fields (#705)

* Only infer firebase if publisher not provided as part of user input in ext:info flow (#708)

* Adds new warning prompt for non-trusted publishers during ext:install (#707)

* add new warning prompt for non-trusted publishers during ext:install

* clean up param namne

* clean up comment

* switch from author ulr to sourceUrl

* no please

* Update copy to link user to documentation on ext:install flow if input not found (#711)

* Adds console install link to ext:dev:publish (#709)

* Adds console install link to ext:dev:publish

* formats

* Add firebase ext:dev:delete command to CLI (#712)

* adds changelog

* formats

Co-authored-by: huangjeff5 <[email protected]>
Co-authored-by: Jeff Huang <[email protected]>
Co-authored-by: Elvis Sun <[email protected]>
devpeerapong pushed a commit to devpeerapong/firebase-tools that referenced this issue Dec 14, 2021
* Add publisher to registry file fields (firebase#686)

* Migrate ext:update ref-based flow to include update warnings + min extension version guard (firebase#684)

* Migrate ext:install flow to install via extension reference and remove EAP gating (firebase#679)

* Remove EAP-specific copy in ext:dev:register and ext:dev:publish command (firebase#691)

* Warn user that unpublishing is final in ext:dev:unpublish command (firebase#693)

* Add extMinVersion flag to ext:dev:unpublish command (firebase#698)

* Migrate ext:info flow to retrieve spec from Registry API (firebase#683)

* Migrate "author" terminology to use "publisher" in Extensions CLI commands (firebase#694)

* Fix bug in confirmInstallByReference and refactor ext:install error messages (firebase#702)

* Fix local path detection logic and refactor warnings logic in ext:update flow (firebase#703)

* Migrate extensions warnings relating to audiences to use (backend) launch stage and visibility fields (firebase#705)

* Only infer firebase if publisher not provided as part of user input in ext:info flow (firebase#708)

* Adds new warning prompt for non-trusted publishers during ext:install (firebase#707)

* add new warning prompt for non-trusted publishers during ext:install

* clean up param namne

* clean up comment

* switch from author ulr to sourceUrl

* no please

* Update copy to link user to documentation on ext:install flow if input not found (firebase#711)

* Adds console install link to ext:dev:publish (firebase#709)

* Adds console install link to ext:dev:publish

* formats

* Add firebase ext:dev:delete command to CLI (firebase#712)

* adds changelog

* formats

Co-authored-by: huangjeff5 <[email protected]>
Co-authored-by: Jeff Huang <[email protected]>
Co-authored-by: Elvis Sun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants