Firebase Emulator --export-on-exit not working properly (Windows 10)

Viewed 1109

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

https://firebase.google.com/docs/emulator-suite/install_and_configure#export_and_import_emulator_data

When I run npm run em-startup, the emulator starts up as expected, I can create collections/docs, etc. in the Emulator UI:

> ww@0.1.0 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:

enter image description here

Here is my full project file structure:

enter image description here

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 to data
  • 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.

https://github.com/firebase/firebase-tools/issues/3092

1 Answers

The edited doc is exported in a separate folder with name like 'firebase-export-1654933704513LgLzMo' on exiting the emulator. you have rename it to 'firebase-export' so that the import is done from that file once you start the emulator.

the script is like:

firebase emulators:start --only functions,firestore --import ./firebase-export --export-on-exit ./firebase-export

you have to keep deleting the old one and renaming the latest one for importing the latest data.

Related