firebase-tools: "functions: Failed to load functions source code. Ensure that you have the latest SDK by...."
Version info
> firebase --version
3.17.1
> node --version
v6.12.3
> npm --version
5.6.0
Steps to reproduce
> git clone https://github.com/firebase/functions-samples.git
> cd functions-samples/authenticated-json-api/functions/
> npm install
> grpc@1.8.4 install /Users/karl/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/grpc
> node-pre-gyp install --fallback-to-build --library=static_library
[grpc] Success: "/Users/karl/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/grpc/src/node/extension_binary/node-v48-darwin-x64-unknown/grpc_node.node" is installed via remote
> protobufjs@6.8.4 postinstall /Users/karl/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/protobufjs
> node scripts/postinstall
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN firebase-functions@0.5.9 requires a peer of firebase-admin@~4.2.1 but none is installed. You must install peer dependencies yourself.
added 354 packages in 11.832s
> firebase use my-project
Now using project my-project
> firebase serve --only functions
=== Serving from '/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api'...
i functions: Preparing to emulate functions.
⚠ 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. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.
Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:51:15)
at Object.config (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object.<anonymous> (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/index.js:27:31)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
Actual behavior
> firebase serve --only functions --debug
[2018-01-19T03:30:49.455Z] ----------------------------------------------------------------------
[2018-01-19T03:30:49.459Z] Command: /usr/local/Cellar/node@6/6.12.3/bin/node /usr/local/bin/firebase serve --only functions --debug
[2018-01-19T03:30:49.460Z] CLI Version: 3.17.1
[2018-01-19T03:30:49.460Z] Platform: darwin
[2018-01-19T03:30:49.460Z] Node Version: v6.12.3
[2018-01-19T03:30:49.460Z] Time: Thu Jan 18 2018 22:30:49 GMT-0500 (EST)
[2018-01-19T03:30:49.461Z] ----------------------------------------------------------------------
[2018-01-19T03:30:49.476Z] > command requires scopes: ["email","openid","https://www.googleapis.com/auth/cloudplatformprojects.readonly","https://www.googleapis.com/auth/firebase","https://www.googleapis.com/auth/cloud-platform"]
[2018-01-19T03:30:49.476Z] > authorizing via signed-in user
[2018-01-19T03:30:49.479Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/projects/my-project
Thu Jan 18 2018 22:30:49 GMT-0500 (EST)
[2018-01-19T03:30:49.855Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 19 Jan 2018 03:30:49 GMT, content-type=application/json; charset=utf-8, content-length=126, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
[2018-01-19T03:30:49.856Z] >>> HTTP REQUEST GET https://admin.firebase.com/v1/database/my-project/tokens
Thu Jan 18 2018 22:30:49 GMT-0500 (EST)
[2018-01-19T03:30:50.482Z] <<< HTTP RESPONSE 200 server=nginx, date=Fri, 19 Jan 2018 03:30:50 GMT, content-type=application/json; charset=utf-8, content-length=267, connection=close, x-content-type-options=nosniff, strict-transport-security=max-age=31536000; includeSubdomains, cache-control=no-cache, no-store
=== Serving from '/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api'...
i functions: Preparing to emulate functions.
[2018-01-19T03:30:51.081Z] Fetching environment
[2018-01-19T03:30:51.082Z] >>> HTTP REQUEST GET https://appengine.googleapis.com/v1/apps/my-project
Thu Jan 18 2018 22:30:51 GMT-0500 (EST)
[2018-01-19T03:30:51.083Z] >>> HTTP REQUEST GET https://apikeys.googleapis.com/v1/projects/my-project/apiKeys
Thu Jan 18 2018 22:30:51 GMT-0500 (EST)
[2018-01-19T03:30:51.569Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Fri, 19 Jan 2018 03:30:51 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35", accept-ranges=none, connection=close
[2018-01-19T03:30:51.663Z] <<< HTTP RESPONSE 200 content-type=application/json; charset=UTF-8, vary=X-Origin, Referer, Origin,Accept-Encoding, date=Fri, 19 Jan 2018 03:30:51 GMT, server=ESF, cache-control=private, x-xss-protection=1; mode=block, x-frame-options=SAMEORIGIN, x-content-type-options=nosniff, alt-svc=hq=":443"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000; v="41,39,38,37,35", accept-ranges=none, connection=close
[2018-01-19T03:30:51.664Z] Starting @google-cloud/functions-emulator
[2018-01-19T03:30:53.220Z] Parsing function triggers
⚠ 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. Please ensure you have the latest firebase-functions SDK by running "npm i --save firebase-functions@latest" inside your functions folder.
Error: Firebase config variables are not available. Please use the latest version of the Firebase CLI to deploy this function.
at init (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:51:15)
at Object.config (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/node_modules/firebase-functions/lib/config.js:29:9)
at Object.<anonymous> (/Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/index.js:27:31)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
It’s very strange, because in other projects, firebase serve --only functions
freezes, and I tried a bunch of other samples. It doesn’t work in any of them.
It even doesn’t work for functions I already have deployed.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 4
- Comments: 60 (15 by maintainers)
Try running
npm run serve
from inside the functions directory instead offirebase serve --only functions
, this may or may not work depending on how your package.json file is configured.I’ve managed to work around this error by downgrading
firebase-tools
to 3.16.0, since the error started after I updated to 3.17.1Longer story
I first stumbled upon this error in my CI runner, bc I was installing the latest version of
firebase-tools
for deployment. Overnight, my deploys stopped working. They started working again after I upgradedfirebase-admin
andfirebase-functions
.But then my local environment stopped working. I could still deploy, but couldn’t serve functions. Tried uninstalling
firebase-tools
and reinstalling… And all variations I could come up with (cleaning cache, using the latest NPM, using 6.11.5, using Yarn, etc.). No luck.Finally, I decided to roll everything back to the versions that were working before and froze the version used in my CI script (instead of using the latest) and now both environments work consistently.
I’ve seen different variations of this issue with different possible solutions dating a few months back. Maybe it’s a regression? Some obscure underlying issue?
BTW: I’m running macOS High Sierra 10.13.2 locally and the node:latest Docker image for my CI runner on GitLab, if that helps.
PS: In my experience,
npm run dev
runsfirebase serve --only functions
internally.@mono0926 We never supported custom config values inside of the emulator, you need to run “firebase functions:config:get > .runtimeconfig.json” inside your functions folder so the variables get stored in .runtimeconfig.json and can be accessed by the emulator.
@marcus7777 I think this is a separate issue, captured in https://github.com/firebase/firebase-tools/issues/442
I’m closing this issue now since the originally reported error is fixed in v.3.17.3
v3.17.2 has now been released and should have fixed the problem, please let me know if it doesn’t. Thanks for reporting!
Hi everyone, the latest firebase-tools (3.17.1) also requires the latest firebase-functions SDK, so the better way to solve the problems would be to run “npm i --save firebase-functions@latest” inside the functions folder prior to deploying or serving, as the error message suggests.
@rafasoares : thank you, can confirm that downgrading to 3.16.0 fixed the error!
I’m using macOS High Sierra 10.13.2 too, but I’m using node v6.11.5 installed through
nvm
.In my case, I fixed the bug by running
firebase deploy
first then runfirebase serve
and the bug went awayI have the exact same issue. I think we’re just going to bail on using environmental variables in our various deployment stages and just use a JSON config file. I would love to see a fix, running npm does absolutely nothing to fix this.
@Jhony0311 you’re probably also affected by #691
@laurenzlong
I had same problem as @rafasoares, and I tried
npm install -g https://github.com/firebase/firebase-tools.git#laurenzlong-patch-1
, but the problem remains.By
npm install -g firebase-tools@3.16.0
, the problem is resolved.Update: If I replace the
functions.config().firebase
call with the following JSON, it works:That JSON was the output of
functions.config().firebase
when usingfirebase-tools@3.16.0
(with the exception of thecredential
bit, which I got from the docs.I haven’t tried deploying with this code, though.
It didn’t work for me. I managed to make it work on a blank project, but couldn’t make my current project work.
So I went digging. What are the differences between the two?
I was able to pinpoint the issue. It breaks when I add this bit of code:
If I remove the initialization bit, I can serve the functions. However, I can’t use Firestore.
You actually don’t need to set GOOGLE_APPLICATION_CREDENTIALS if you’re not using Firebase auth or other Google APIs. So @BernalCarlos I think your issue is the same as https://github.com/firebase/firebase-tools/issues/691, which I’ve made a fix for and linked to in that issue.
@laurenzlong
I see. I forgot to write this information. This is
functions/.runtimeconfig.json
:I was able to access
functions.config().environment. project_id
at under v3.16.0, but I cannot access at latest version(v3.17.3).Hello,
I’m also having this problem with firebase-tools@3.17.5.
As noted by @rafasoares the problem appears if I add this line:
admin.initializeApp(functions.config().firebase);
This is the error I’m getting:
Also when I downgrade to
firebase-tools@3.16.0
I’m able to access the shell, but a new error appears:@laurenzlong Maybe there is something I’m missing?
@marcus7777 the problem you are facing is unrelated to this is issue. Try removing firebase-tools and reinstalling it. If it doesn’t work, open a new issue.
Just tried v3.17.2, worked for me!
@rafasoares Apologies, I missed that part. I’ll look into it now.