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

"functions: Failed to load functions source code. Ensure that you have the latest SDK by...." #609

Closed
The-Alchemist opened this issue Jan 19, 2018 · 60 comments · Fixed by #619

Comments

@The-Alchemist
Copy link

The-Alchemist commented Jan 19, 2018

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.

@dylanjmcdonald
Copy link

dylanjmcdonald commented Jan 19, 2018

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.

@The-Alchemist
Copy link
Author

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?

@dylanjmcdonald
Copy link

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

@rafasoares
Copy link

rafasoares commented Jan 19, 2018

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.

@The-Alchemist
Copy link
Author

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

npm install -g firebase-tools@3.16.0

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

@rafasoares
Copy link

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

@laurenzlong
Copy link
Contributor

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
Copy link

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

@laurenzlong
Copy link
Contributor

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

@laurenzlong
Copy link
Contributor

#614

@rafasoares
Copy link

Awesome! Thanks!

@laurenzlong
Copy link
Contributor

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

@The-Alchemist
Copy link
Author

Just tried v3.17.2, worked for me!

@rafasoares
Copy link

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.

@rafasoares
Copy link

rafasoares commented Jan 19, 2018

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 firebase-tools@3.16.0 (with the exception of the credential bit, which I got from the docs.

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

@laurenzlong
Copy link
Contributor

laurenzlong commented Jan 19, 2018

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

@laurenzlong laurenzlong reopened this Jan 20, 2018
@laurenzlong
Copy link
Contributor

@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

@mono0926
Copy link

@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 firebase-tools@3.16.0, the problem is resolved.

@rafasoares
Copy link

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/functions-emulator@1.0.0-alpha.23 is the installed version.

@laurenzlong
Copy link
Contributor

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

Thanks for your patience and help!

@mono0926
Copy link

@laurenzlong

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

This still gives me the error, unfortunately :(

@laurenzlong
Copy link
Contributor

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

@mono0926
Copy link

@laurenzlong

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

I already tried that.

@rafasoares
Copy link

rafasoares commented Jan 20, 2018

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 > node-uuid@1.4.8: Use uuid module instead
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 📃  Building fresh packages...
success Installed "firebase-tools@3.17.2" 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?

@laurenzlong
Copy link
Contributor

@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 #442

I'm closing this issue now since the originally reported error is fixed in v.3.17.3

@rafasoares
Copy link

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

@mono0926
Copy link

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

@laurenzlong
Copy link
Contributor

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

@mono0926
Copy link

@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 👍 : #629

@marcus7777
Copy link

just update to 3.17.4 still get:

sudo npm install -g firebase-tools
[sudo] password for marcus: 
npm WARN deprecated node-uuid@1.4.8: Use uuid module instead
/usr/bin/firebase -> /usr/lib/node_modules/firebase-tools/bin/firebase
+ firebase-tools@3.17.4
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)

@rafasoares
Copy link

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

@bmenasha
Copy link

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

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

and similar files.
thanks

@BernalCarlos
Copy link

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:

➜  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 firebase-tools@3.16.0 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?

@laurenzlong
Copy link
Contributor

@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

@BernalCarlos
Copy link

BernalCarlos commented Mar 8, 2018

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

@laurenzlong
Copy link
Contributor

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.

@BernalCarlos
Copy link

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

folder-structure.txt

@Rulsky
Copy link

Rulsky commented Mar 8, 2018

With firebase-tools@3.17.5 (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: #691

@BernalCarlos
Copy link

BernalCarlos commented Mar 8, 2018

@Rulsky with irebase-tools@3.17.4, 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?

@Rulsky
Copy link

Rulsky commented Mar 8, 2018

@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

@laurenzlong
Copy link
Contributor

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 #691, which I've made a fix for and linked to in that issue.

@Jhony0311
Copy link

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

@laurenzlong
Copy link
Contributor

@Jhony0311 you're probably also affected by #691

@sturmenta
Copy link

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?

@Rulsky
Copy link

Rulsky commented Jul 4, 2018 via email

@AskYous
Copy link

AskYous commented Aug 15, 2018

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.

@websocketdev
Copy link

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.

@bodadotsh
Copy link

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

@Randyanto
Copy link

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.

@takumabo
Copy link

takumabo commented Jun 6, 2020

@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 'firebase@5.9.0'.
I did npm install --save firebase@5.9.0. 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.

yuchenshi pushed a commit that referenced this issue Sep 18, 2024
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

Successfully merging a pull request may close this issue.