Firebase-tools: "functions: Failed to load functions source code. Ensure that you have the latest SDK by...."

Created on 19 Jan 2018  ·  60Comments  ·  Source: firebase/firebase-tools

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

> [email protected] 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

> [email protected] 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 [email protected] 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.

Most helpful comment

Try running npm run serve from inside the functions directory instead of firebase serve --only functions, this may or may not work depending on how your package.json file is configured.

All 60 comments

Try running npm run serve from inside the functions directory instead of firebase serve --only functions, this may or may not work depending on how your package.json file is configured.

Unfortunately, I don't have a package.json configured for that.

> npm run serve
npm ERR! Darwin 17.3.0
npm ERR! argv "/Users/alchemist/.nvm/versions/node/v6.11.5/bin/node" "/Users/karl/.nvm/versions/node/v6.11.5/bin/npm" "run" "serve"
npm ERR! node v6.11.5
npm ERR! npm  v3.10.10

npm ERR! missing script: serve
npm ERR!
npm ERR! If you need help, you may report this error at:
npm ERR!     <https://github.com/npm/npm/issues>

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/alchemist/Development/git/learnics/functions-samples/authenticated-json-api/functions/npm-debug.log

Can you point me to one?

This is what mine looks like after a fresh firebase init: https://gist.github.com/dylanjmcdonald/6c033b476e863efaea3eccc0b3137772

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

Longer 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 upgraded firebase-admin and firebase-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 runs firebase serve --only functions internally.

@rafasoares : thank you, can confirm that downgrading to 3.16.0 fixed the error!

npm install -g [email protected]

I'm using macOS High Sierra 10.13.2 too, but I'm using node v6.11.5 installed through nvm.

@The-Alchemist glad I could help.

I've tried both with the latest node installed via brew (9.x) and 6.11.5 installed through nvm. It was working before with the latest node (with the GCP node version warning, though).

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.

@laurenzlong did you read my comment above? It was the first thing I tried. After that, I was able to firebase deploy --only functions, but not firebase serve --only functions.

And I've tried all manner of cleanup strategies I could come up with. I even deleted my working copy and pulled everything from Git from scratch.

@rafasoares Apologies, I missed that part. I'll look into it now.

Awesome! Thanks!

v3.17.2 has now been released and should have fixed the problem, please let me know if it doesn't. Thanks for reporting!

Just tried v3.17.2, worked for me!

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:

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase); // <-- Specifically, this line

If I remove the initialization bit, I can serve the functions. However, I can't use Firestore.

Update: If I replace the functions.config().firebase call with the following JSON, it works:

{
  databaseURL: 'https://[PROJECT_NAME].firebaseio.com',
  storageBucket: '[PROJECT_NAME].appspot.com',
  apiKey: '[API KEY]',
  authDomain: '[PROJECT_NAME].firebaseapp.com',
  projectId: '[PROJECT_NAME]',
  credential: admin.credential.applicationDefault()
}

That JSON was the output of functions.config().firebase when using [email protected] (with the exception of the credential bit, which I got from the docs.

I haven't tried deploying with this code, though.

@rafasoares I downgraded the google-cloud/functions-emulator dependency, that's the difference. Try "npm uninstall -g firebase-tools & npm i -g firebase-tools". Depending on the npm version you have, sometimes it doesn't downgrade dependencies unless you do an uninstall first.

@rafasoares Seems like I got semver versioning wrong, I think I fixed it in #618, can you try using that branch?

npm install -g https://github.com/firebase/firebase-tools.git#laurenzlong-patch-1

@laurenzlong

Seems like I got semver versioning wrong, I think I fixed it in #618, can you try using that branch?

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 [email protected], the problem is resolved.

I'm sorry, I have been playing around with Yarn and NPM trying to get them to download the right version, I've probably messed up my environment haha.

But yeah, https://github.com/firebase/firebase-tools.git#laurenzlong-patch-1 still gives me the error, even though @google-cloud/[email protected] is the installed version.

@mono0926 @rafasoares How about this?
npm install -g https://github.com/firebase/firebase-tools.git#ll-fixemu

Thanks for your patience and help!

@laurenzlong

npm install -g https://github.com/firebase/firebase-tools.git#ll-fixemu

This still gives me the error, unfortunately :(

what about npm uninstall -g firebase-tools && npm install -g https://github.com/firebase/firebase-tools.git#ll-fixemu

@laurenzlong

what about npm uninstall -g firebase-tools && npm install -g https://github.com/firebase/firebase-tools.git#ll-fixemu

I already tried that.

Apparently https://github.com/firebase/firebase-tools.git#ll-fixemu fixes it for me.

$ yarn global remove firebase-tools
yarn global v1.3.2
[1/2] Removing module firebase-tools...
[2/2] Regenerating lockfile and installing missing dependencies...
success Uninstalled packages.
✨  Done in 3.91s.
$ yarn global add https://github.com/firebase/firebase-tools.git\#ll-fixemu
yarn global v1.3.2
[1/4] 🔍  Resolving packages...
warning https://github.com/firebase/firebase-tools.git#ll-fixemu > universal-analytics > [email protected]: Use uuid module instead
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
success Installed "[email protected]" with binaries:
      - firebase
✨  Done in 11.73s.
$ firebase --version
3.17.2
$ firebase serve --only functions

=== Serving from '/Users/[USERNAME]/dev/projects/[PROJECT NAME]'...

i  functions: Preparing to emulate functions.
✔  functions: createUrl: http://localhost:5000/[PROJECT NAME]/us-central1/createUrl
✔  functions: getUrl: http://localhost:5000[PROJECT NAME]us-central1/getUrl

I'm currently using node v6.11.5. @mono0926 maybe that has got something to do with it?

@rafasoares

I'm currently using node v6.11.5. @mono0926 maybe that has got something to do with it?

I'm using same version of node 🤔

@mono0926 yeah, I was just guessing. I just tried using latest and it worked.

Try doing a thorough cleanup of your global dependencies and a cache clean (also, try rebuilding the local dependencies of your project). I've done that several times today while trying to solve this issue, maybe it helped.

@rachelmyers @laurenzlong

I noticed that the error detail changed, after trying npm install -g https://github.com/firebase/firebase-tools.git#ll-fixemu.

And, the error occurred at my code, and I modified it, and after that the error resolved 👍

If I use [email protected], the error doesn't occur without modifying my code.
So, I'll tell you later, I investigated the problem detail.

@mono0926 Do you mind sharing with us what you changed in your code? Was it something related to Firebase?

@rachelmyers @laurenzlong

I investigated that and I figured out the point.

With this code,

import * as functions from 'firebase-functions';
import * as util from 'util';
console.error(`environment: ${util.inspect(functions.config().environment.project_id)}`);

The error occurs:

TypeError: Cannot read property 'project_id' of undefined

But with this code,

import * as functions from 'firebase-functions';
import * as util from 'util';
console.error(`environment: ${util.inspect(functions.config().environment)}`);

This log is printed:

info: environment: { project_id: 'development' }

Why cannot I access project_id of functions.config().environment at latest version?
I was able to access project_id of functions.config().environment under [email protected].

I know this is another problem with this issue.

Do you mind sharing with us what you changed in your code? Was it something related to Firebase?

I fix the issue by hard coding project_id value temporarily, so I'd like you to fix the issue.

When I deployed the functions, the problem doesn't occur.

@The-Alchemist I Confirm it me too: downgrading to 3.16.0 fixed the error!

npm install -g [email protected]

I'm using macOS High Sierra 10.13.2 too and node v8.9.4 installed by its installer with fixed permission: https://docs.npmjs.com/getting-started/fixing-npm-permissions.

No problems with [email protected] on Windows.

I get :

+ [email protected]
updated 1 package in 50.957s
(xenial)marcus@localhost:~/app$  firebase serve --only functions

=== Serving from '/home/marcus/app'...

⚠  functions: Cannot start emulator. Error: Cannot find module '/usr/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/grpc_node.node'

Marcus: --only functions (plural)

On Sat, Jan 20, 2018, 12:44 PM Marcus Hitchins notifications@github.com
wrote:

I get :

=== Serving from '/home/marcus/app'...

Error: Cannot understand what targets to deploy. Check that you specified valid targets if you used the --only or --except flag. Otherwise, check your firebase.json to ensure that your project is initialized for the desired features.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/firebase/firebase-tools/issues/609#issuecomment-359200751,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAAD_tJH6ez89mjEZVdJbPVMDqeKym76ks5tMlAQgaJpZM4Rj8M0
.

@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

It's amazing how quickly this was dealt with. Awesome work @laurenzlong. 👏

@laurenzlong

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.

I see. I forgot to write this information.
This is functions/.runtimeconfig.json:

{
  "environment": {
    "project_id": "development"
  }
}

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

@mono0926 Can you open a new issue for this? And also include what version of firebase-functions you are using?

@laurenzlong

Can you open a new issue for this? And also include what version of firebase-functions you are using?

Okay, I opened an issue 👍 : https://github.com/firebase/firebase-tools/issues/629

just update to 3.17.4 still get:

sudo npm install -g firebase-tools
[sudo] password for marcus: 
npm WARN deprecated [email protected]: Use uuid module instead
/usr/bin/firebase -> /usr/lib/node_modules/firebase-tools/bin/firebase
+ [email protected]
updated 4 packages in 555.594s
(xenial)marcus@localhost:~$ cd app/
(xenial)marcus@localhost:~/app$ firebase serve --only functions

=== Serving from '/home/marcus/Downloads/deko-app'...

⚠  functions: Cannot start emulator. Error: Cannot find module '/usr/lib/node_modules/firebase-tools/node_modules/grpc/src/node/extension_binary/grpc_node.node'
(xenial)marcus@localhost:~/app$

and has tryed #442 but no luck.
ps. run on xenial (Linux)

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

I also had success deleting the local state of the emulator:

$HOME/.config/configstore/@google-cloud/functions-emulator/.functions.json

and similar files.
thanks

Hello,

I'm also having this problem with [email protected].

As noted by @rafasoares the problem appears if I add this line:

admin.initializeApp(functions.config().firebase);

This is the error I'm getting:

➜  functions yarn run shell
yarn run v1.5.1
$ yarn run build && firebase experimental:functions:shell
$ tsc
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. 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 (/Volumes/HDD/carlosbernal/Dropbox/Wanttu/Futbol/backend/functions/node_modules/firebase-functions/lib/config.js:55:15)
    at Object.config (/Volumes/HDD/carlosbernal/Dropbox/Wanttu/Futbol/backend/functions/node_modules/firebase-functions/lib/config.js:29:9)
    at Object.<anonymous> (/Volumes/HDD/carlosbernal/Dropbox/Wanttu/Futbol/backend/functions/lib/index.js:5:35)
    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)
No functions emulated.
✨  Done in 11.64s.

Also when I downgrade to [email protected] I'm able to access the shell, but a new error appears:

➜  functions yarn run shell
yarn run v1.5.1
$ yarn run build && firebase experimental:functions:shell
$ tsc
i  functions: Preparing to emulate functions.
⚠  functions: Error from emulator. TypeError: Cannot read property 'split' of undefined
✔  functions: addMessage
firebase >

@laurenzlong Maybe there is something I'm missing?

@BernalCarlos As the error message suggests, please make sure you are on the latest firebase-functions version. Run the following in your functions directory: `npm i --save firebase-functions@latest'

Afterwards, your functions/package.json should have firebase-functions 0.8.1

@laurenzlong I already have the latest version of firebase-functions. This is my package.json:

{
  "name": "functions",
  "scripts": {
    "lint": "tslint --project tsconfig.json",
    "build": "tsc",
    "serve": "yarn run build && firebase serve --only functions",
    "shell": "yarn run build && firebase experimental:functions:shell",
    "start": "yarn run shell",
    "deploy": "firebase deploy --only functions",
    "logs": "firebase functions:log"
  },
  "main": "lib/index.js",
  "dependencies": {
    "firebase-admin": "^5.9.1",
    "firebase-functions": "^0.8.1"
  },
  "devDependencies": {
    "tslint": "^5.9.1",
    "typescript": "^2.7.2"
  },
  "private": true
}

In the yarn.lock I also have this:

...

firebase-functions@^0.8.1:
  version "0.8.1"
  resolved "https://registry.yarnpkg.com/firebase-functions/-/firebase-functions-0.8.1.tgz#a42fe6d243862c406af16e1c16b1d0a81ec24c03"
  dependencies:
    "@types/express" "^4.0.33"
    "@types/jsonwebtoken" "^7.1.32"
    "@types/lodash" "^4.14.34"
    "@types/sha1" "^1.1.0"
    express "^4.0.33"
    jsonwebtoken "^7.1.9"
    lodash "^4.6.1"
    sha1 "^1.1.1"

...

firebase-admin@^5.9.1:
  version "5.9.1"
  resolved "https://registry.yarnpkg.com/firebase-admin/-/firebase-admin-5.9.1.tgz#1edf6248d014063f0e473f84fe9d63df18e53807"
  dependencies:
    "@firebase/app" "^0.1.10"
    "@firebase/database" "^0.1.11"
    "@google-cloud/firestore" "^0.12.0"
    "@google-cloud/storage" "^1.6.0"
    "@types/google-cloud__storage" "^1.1.7"
    "@types/node" "^8.0.53"
    faye-websocket "0.9.3"
    jsonwebtoken "8.1.0"
    node-forge "0.7.1"

But the problem is still present.

Thanks for sharing your package.json, can you tell me what your project directory structure is? We do not yet support mono repos, so there needs to be a functions/node_modules/firebase-functions folder.

Sure @laurenzlong this my project directory structure, it quite big because of the node_modules folder:

folder-structure.txt

With [email protected] (i.e firebase CLI) problem appears again, it does not related directly to functions, but if you roll back to 3.17.4 emulation will work.
I opened corresponding issue in firebase-tools repo: firebase/firebase-tools#691

@Rulsky with [email protected], it fails with a different error for a very simple function:

// index.ts

import * as fbAdmin from "firebase-admin";
import * as fbFunctions from "firebase-functions";

fbAdmin.initializeApp(fbFunctions.config().firebase);

export const addMessage = fbFunctions.https.onRequest((request, response) => {
    const original = request.query.text;
    response.send(original);
});

Error:

➜  functions yarn run shell
yarn run v1.5.1
$ yarn run build && firebase experimental:functions:shell
$ tsc
i  functions: Preparing to emulate functions.
⚠  functions: Failed to emulate addMessage
No functions emulated.
✨  Done in 12.71s.

Also I noticed that a log file is created when the firebase CLI is running, but such file gets deleted immediately after. Is there a way to keep this log file from being deleted?

@BernalCarlos have you put service Admin key into your project's functions dir? And made an export of GOOGLE_APPLICATION_CREDENTIALS global variable in your shell?
it is crucial to make it work https://firebase.google.com/docs/functions/local-emulator

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.

I have a clean project just with the function that the CLI creates and is not working when I include const app = admin.initializeApp(functions.config().firebase);. The project was setup with
```
"dependencies": {
"firebase-admin": "~5.8.1",
"firebase-functions": "^0.8.1"
}
````

@Jhony0311 you're probably also affected by #691

I can use firebase deploy --only functions but no firebase serve --only functions.

It stays loading after executing "npm run serve",

i functions: Preparing to emulate functions.
Warning: You're using Node.js v10.5.0 but Google Cloud Functions only supports v6.11.5.
⚠ functions: Failed to emulate getSomeData
i functions: No HTTPS functions found. Use firebase functions:shell if you would like to emulate other types of functions.

firebase version: 3.19.3

This is my code:

'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

exports.getSomeData = functions.https.onRequest((req, res) => {
  admin.firestore().doc('feedback/d8pGxmML5ZKLYEy5jyhm').get()
    .then(doc => res.send(doc.data()))
    .catch(err => res.status(500).send(err));
});

Any suggestions?

Hi, problem with node 10
Use older version. Version 8, for example.
On 4 Jul 2018, 01:46 +0200, Nicolas Sturm notifications@github.com, wrote:

I can use firebase deploy --only functions but no firebase serve --only functions.
It stays loading after executing "npm run serve",
i functions: Preparing to emulate functions.
Warning: You're using Node.js v10.5.0 but Google Cloud Functions only supports v6.11.5.
⚠ functions: Failed to emulate getSomeData
i functions: No HTTPS functions found. Use firebase functions:shell if you would like to emulate other types of functions.
firebase version: 3.19.3
This is my code:
'use strict';

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp();

exports.getSomeData = functions.https.onRequest((req, res) => {
admin.firestore().doc('feedback/d8pGxmML5ZKLYEy5jyhm').get()
.then(doc => res.send(doc.data()))
.catch(err => res.status(500).send(err));
});
Any suggestions?

You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.

In case it helps others, I was trying to use fulfillments of Dialogflow and edit & test the code locally. I had this error. What solved it was similar to what @rafasoares said.

To solve this, I had to copy the package.json Dialogflow used rather than the one firebase init generated. Seems to be a versioning issue.

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

In my case, I fixed the bug by running firebase deploy first then run firebase serve and the bug went away

I have updated all firebase-tools, firebase-admin, firebase-functions to the latest one

"dependencies": {
    "firebase-admin": "^7.3.0",
    "firebase-functions": "^2.3.0",
    "googleapis": "^32.0.0",
    "mailgun-js": "^0.18.0",
    "moment": "^2.20.1",
    "request": "^2.81.0",
    "request-promise": "^4.2.1"
  },
  "private": true,
  "devDependencies": {
    "firebase-functions-test": "^0.1.2",
    "firebase-tools": "^6.8.0",
    "mocha": "^5.2.0",
    "rewire": "^4.0.1",
    "sinon": "^6.0.0",
    "underscore": "^1.9.1"
  },

However, I still see this error when I want to run firebase functions shell

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. Error occurred while parsing your function triggers.

@Randyanto hello, I can't tell you clear answer but I may give you some clues. I got the same error too. In my case, I couldn't work require('firebase')well. So, I tried downgrade '[email protected]'.
I did npm install --save [email protected]. Finally, I could solve this problem.
Maybe you have the problem of relating around firebase or other functions.
Check out the each version dependencies you have. Good luck.

Was this page helpful?
0 / 5 - 0 ratings