Description
Related issues
[REQUIRED] Version info
node: 16.5
firebase-functions: 3.14.1
firebase-tools: 9.16.0
firebase-admin: 9.11.0
[REQUIRED] Test case
The issue/question is generic in nature, but steps to reproduce are added below. In addition, logs are available in this discussion.
I noticed yesterday that the functions/index.js
gets imported three times at the launch of Firebase Emulators, and thought this strange.
Having checked the Getting Started section, I found no mention about this. Not sure if it is a feature of the Firebase Emulators or the Cloud Functions implementation, in general.
Why this matters?
People do initialisation in the module body. If such things are time-taking, it is good to know that the body is called 1 + (number of functions in it)
times, at initialisation. If this is intended, I think it should be mentioned in the docs.
The sample code shows initialising admin.initializeApp();
in the module body.
When moving to ES modules, this becomes even more important. EcmaScript modules are intended to be imported only once, and cached, so authors naturally expect such behaviour. I am not asking for change of implementation. I am asking for clarifying these things in the documentation.
[REQUIRED] Steps to reproduce
$ git clone https://github.com/akauppi/GroundLevel-firebase-es.git
$ cd GroundLevel-firebase-es
$ git checkout next
$ npm install
...
$ cd packages/backend
# Edit 'functions/index.js', adding a logging for "__LOADED__" or similar.
$ npm run start
[REQUIRED] Expected behavior
The functions/index.js
gets loaded once.
[REQUIRED] Actual behavior
The functions/index.js
gets loaded 3 times.
- first, before the green lines about functions having loaded are shown
- once for each function included in it
Were you able to successfully deploy your functions?
Yes.
I haven't observed what the behaviour in the cloud is.