question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

firebase.json 'functions.ignore' bloats package upload

See original GitHub issue

Environment info

firebase-tools:

firebase --version
7.2.2

Platform: Both MacOS (10.14.6 (18G87)) & Windows 10 development environments.

Test case

MCVE: Firebase functions template + a ‘functions.ignore’ section in firebase.json

Steps to reproduce

Create a firebase project.

Run firebase init functions with default options, and add it to your new project:

firebase init functions

Uncomment the helloWorld sample function in index.js and deploy:

⋊> ~/D/f/functions firebase deploy                                                                                    11:02:38

=== Deploying to 'test-function-deploy-3a957'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (22.95 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: updating Node.js 8 function helloWorld(us-central1)...
✔  functions[helloWorld(us-central1)]: Successful update operation. 

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/test-function-deploy-3a957/overview
⋊> ~/D/f/functions

Note the deployed packaged functions size (22.95KB).

Edit firebase.json to include a ‘functions.ignore’ section:

{
  "functions": {
    "ignore": []
  }
}

Deploy again:

⋊> ~/D/f/functions firebase deploy                                                                                    11:03:24

=== Deploying to 'test-function-deploy-3a957'...

i  deploying functions
i  functions: ensuring necessary APIs are enabled...
✔  functions: all necessary APIs are enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (9.07 MB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: updating Node.js 8 function helloWorld(us-central1)...
✔  functions[helloWorld(us-central1)]: Successful update operation. 

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/test-function-deploy-3a957/overview
⋊> ~/D/f/functions 

Note that the deployed package has grown from 22.95KB to 9.07MB.

Expected behavior

I expect that if things are ignored, the deployed package gets smaller rather than larger.

Actual behavior

The deployed package increases in size by several orders of magnitude from 22.95KB to 9.07MB.

For reference, the size of the functions folder including local node_modules is 29MB in this case. The node_modules folder itself is 28.9MB on disk, and is ~6MB gzipped.

This also affects TypeScript projects, presumably because the issue is triggered after the tsc part of things.

Comment

I haven’t yet found any good/definitive documentation for the firebase.json configuration file and specifically the functions section. There is some documentation of the hosting section here. My understanding of thefunctions.ignore structure/usage is currently based on https://github.com/firebase/firebase-tools/issues/291#issuecomment-322526710.

There is a related issue #429 where @laurenzlong indicates that the ignore section should be operational/fixed.

Open question

Where is the deployed package built to locally, before deploying? I ran with --debug and couldn’t figure out any useful file paths.

Thanks!

Thanks for considering! And my phone tethering data plan thanks you for resolving this, as my current project deploy is ~55MB before I figured out what was going on 😃

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:3
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

28reactions
lookfirstcommented, Jun 19, 2020

@bkendall Why not document it?

8reactions
bkendallcommented, Aug 15, 2019

The behavior that you described is the behavior that I would expect.

The documentation does not describe functions.ignore, as you pointed out; however, it is used by the CLI.

Unofficially (in that it is undocumented), firebase.ignore has a default of ["node_modules"]. This lets us limit the amount of stuff we have to upload during the deploy (which you can imagine could become very large, very quickly). By setting firebase.ignore in package.json, it tells the CLI that nothing should be ignored. Now, the node_modules folder is included in the archive and sent to Functions.

To answer your question: at a high-level description of the process, the CLI doesn’t build a package locally. It does roughly the following:

  1. Runs any predeploy script for functions (also specified in firebase.json).
  2. Parses the source code for functions to deploy.
  3. Zips the source code (usually ignoring node_modules) and uploads it to Functions.

Once the source code is uploaded, the Functions infrastructure runs npm install for the package.json and the source is ready to go and serve users (at least, in this super hand-wavy explanation).

I hope that answers your questions. But since there’s no CLI-related bug here, I’m going to close this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Manage functions | Cloud Functions for Firebase - Google
You can deploy, delete, and modify functions using Firebase CLI commands or by setting runtime options in your functions source code. Deploy functions....
Read more >
Deploy Next.js app to Firebase Functions with existing functions
This is what I mean by "bloating" a function. ... Add the following to the /function folder's package.json file:
Read more >
Cloud Functions for Firebase、デプロイ周りでのメモ - Zenn
Cloud Functions for Firebaseでも、デプロイするファイルをignoreできる ... 2019) firebase.json 'functions.ignore' bloats package upload #1602.
Read more >
Resumable uploads | Cloud Storage - Google Cloud
Once Cloud Storage persists bytes in a resumable upload, those bytes cannot be overwriten, and Cloud Storage ignores attempts to do so. Because...
Read more >
How to host a Sapper.js SSR app on Firebase.
Recently an error pops up if the firebase-admin dependency in functions/package.json is greater than 7, so just set it to:.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found