I have been experimenting with using Firebase emulators to decrease the number of reads/writes against my actual Firestore db while I am developing a web app. More specifically, I would like to create some re-useable test data from the Emulator UI to work with as I am developing my app, before I deploy to production.
I saw there are options to export data from the Emulator UI and re-import them in later sessions, so after following the docs, I have setup a simple npm script in package.json
:
"em-startup": "firebase emulators:start --export-on-exit=data"
.
When I run npm run em-startup
, the emulator starts up as expected, I can create collections/docs, etc. in the Emulator UI:
> [email protected] em-startup
> firebase emulators:start --export-on-exit=data
i emulators: Starting emulators: auth, firestore, database, hosting, pubsub, storage
! emulators: It seems that you are running multiple instances of the emulator suite for project drew-daniels-wheres-waldo. This may result in unexpected behavior.
i firestore: Firestore Emulator logging to firestore-debug.log
i database: Database Emulator logging to database-debug.log
i pubsub: Pub/Sub Emulator logging to pubsub-debug.log
i hosting: Serving hosting files from: build
+ hosting: Local server: http://localhost:5000
i ui: Emulator UI logging to ui-debug.log
┌─────────────────────────────────────────────────────────────┐
│ ✔ All emulators ready! It is now safe to connect your app. │
│ i View Emulator UI at http://localhost:4000 │
└─────────────────────────────────────────────────────────────┘
┌────────────────┬────────────────┬─────────────────────────────────┐
│ Emulator │ Host:Port │ View in Emulator UI │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Authentication │ localhost:9099 │ http://localhost:4000/auth │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Firestore │ localhost:8080 │ http://localhost:4000/firestore │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Database │ localhost:9000 │ http://localhost:4000/database │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Hosting │ localhost:5000 │ n/a │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Pub/Sub │ localhost:8085 │ n/a │
├────────────────┼────────────────┼─────────────────────────────────┤
│ Storage │ localhost:9199 │ http://localhost:4000/storage │
└────────────────┴────────────────┴─────────────────────────────────┘
Emulator Hub running at localhost:4400
Other reserved ports: 4500
Issues? Report them at https://github.com/firebase/firebase-tools/issues and attach the *-debug.log files.
but when I ctrl+C
to stop the emulator, PowerShell generates the following output:
i emulators: Received SIGINT (Ctrl-C) for the first time. Starting a clean shutdown.
i emulators: Please wait for a clean shutdown or send the SIGINT (Ctrl-C) signal again to stop right now.
i Automatically exporting data using --export-on-exit "data" please wait for the export to finish...
Terminate batch job (Y/N)? Error: Storage Emulator Rules runtime exited unexpectedly.
i Found running emulator hub for project (my-project-name) at http://localhost:4400
i Exporting data to: C:\Users\MyUserName\my\folder\project\data
i emulators: Received export request. Exporting data to C:\Users\MyUserName\my\folder\project\data.
Additionally, no matter what file path I pass as a parameter in --export-on-exit=
seems to be taken into account, and all that gets exported are files like these output to my project's root directory:
Here is my full project file structure:
It appears that the Firebase emulator is not gracefully shutting down with ctrl+C
and consequently the data from my emulator UI session are not being successfully output and saved in my data
directory.
What I have tried:
- Changing the relative file paths from
./data
todata
- Ensuring all java.exe instances are closed (via task manager)
- Restarting my computer
EDIT There is an open issue on Github regarding this as it appears to be a bug that more people are experiencing. I posted a comment detailing what I'm seeing from my end.
firebase emulators:export ./emulators
(or in your case./data
) before terminating the emulator and not using--export-on-exit
. – Vigilant