firebase-tools: Pub/Sub Emulator has exited with code: 1

[REQUIRED] Environment info

firebase-tools: 11.24.1 Node.js: v16.19.1 Java: OpenJDK 11.0.18

Platform: macOS13.2.1 M1

[REQUIRED] Test case

Run firebase emulators:start --only pubsub

[REQUIRED] Actual behavior

i  emulators: Starting emulators: pubsub
i  pubsub: Pub/Sub Emulator logging to pubsub-debug.log
⚠  pubsub: Fatal error occurred: 
   Pub/Sub Emulator has exited with code: 1, 
   stopping all running emulators
i  pubsub: Stopping Pub/Sub Emulator
kill: usage: kill [-s sigspec | -n signum | -sigspec] pid | jobspec ... or kill -l [sigspec]
⚠  pubsub: Error stopping Pub/Sub Emulator
i  hub: Stopping emulator hub
// pubsub-debug.log
Error: Invalid or corrupt jarfile /Users/ruisi/.cache/firebase/emulators/pubsub-emulator-0.7.1/pubsub-emulator/lib/cloud-pubsub-emulator-0.7.1.jar

I have tried to manually delete cloud-pubsub-emulator-0.7.1.jar, and use firebase setup:emulators:pubsub to reinstall.

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 3
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

😫 I’ve found the real issue.

To be clear, I’m talking about this error:

Error: Invalid or corrupt jarfile …

  • It’s not your Java
  • It’s not your Docker settings (if you run one)
  • Affects any version of firebase-tools

What happens? This issue occurs if you download & set up emulators using node v18.16+ or v19.8+. It works fine if you have emulators installed by other versions of node(I checked only v18.x.x & v19.x.x) even if you upgrade node version afterwards. Since it only happens to pubsub & UI emulators (only those two have to be unzipped after downloading), I suspect that firebase-tools struggle to correctly unpack downloaded archives. firebase-tools have unzipper dependency, hence this may be related: async iteration example no longer works in Node 18x, 19x stream.pipeline [ERR_STREAM_PREMATURE_CLOSE]: Premature close

@christhompsongoogle & firebase team, please take a look at the changelogs for the node versions mentioned above to nail down the exact issue:
v19.8.0 changelog v18.16.0 changelog


For those who is out of luck today and have their docker containers rebuilt and perhaps uses ubuntu as a base image to replicate cloud functions environment, me sharing my dockerfile config to use with a specific node version:

# Trying to replicate the exact cloud functions execution environment
# See https://cloud.google.com/functions/docs/concepts/execution-environment
ARG UBUNTU_VERSION=22.04
ARG NODE_VERSION=18.15.0
ARG JAVA_VERSION=18

FROM ubuntu:$UBUNTU_VERSION as emulators
ARG NODE_VERSION
ARG JAVA_VERSION

RUN apt-get update

ENV HOME=/home/node
ENV NVM_DIR=/usr/local/nvm
ENV NODE_PATH=$NVM_DIR/versions/node/v$NODE_VERSION/bin
ENV PATH=$NODE_PATH:$PATH

# We can install system packages that are available on cloud functions VMs
# Full list of pre-installed packages: https://cloud.google.com/functions/docs/reference/system-packages
RUN apt-get install -y \
    curl \
    openjdk-${JAVA_VERSION}-jre-headless # java is not preinstalled on cloud functions, but is needed to run emulators

# Install nvm, Node
RUN mkdir $NVM_DIR && \
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash && \
    bash $NVM_DIR/nvm.sh ${NODE_VERSION}

# Install firebase-tools and emulators \
RUN npm i -g firebase-tools && \
    firebase setup:emulators:database && \
    firebase setup:emulators:firestore && \
    firebase setup:emulators:pubsub && \
    firebase setup:emulators:storage && \
    firebase setup:emulators:ui

# Preserve firebase emulators cache
VOLUME $HOME/.cache

# Create a user 'node' make him an owner of $HOME
RUN groupadd --gid 1000 node && \
    useradd --uid 1000 --gid node --shell /bin/bash --create-home node && \
    chown -R node:node $HOME

WORKDIR $HOME
USER node
EXPOSE 4000
EXPOSE 5002
EXPOSE 5001
EXPOSE 8080
EXPOSE 8085
EXPOSE 9000
EXPOSE 9005
EXPOSE 9099
EXPOSE 9199
EXPOSE 9299
CMD ["sh"]

maybe it’s not that obvious, but as mentioned in https://github.com/firebase/firebase-tools/issues/5614#issuecomment-1508515106

you can just downgrade to node 18.15. so if you use a node:18 for your image, you can just pin the version to node:18.15 and it should fix the issue temporarily.

Had the same issue today. The following instructions worked for me on macOS:

  1. Delete the downloaded jar file. You can find the directory when you start the emulators with the --debug flag.
  2. Make sure you use NodeJS 16 or 18
  3. Make sure you use Java 17 or 19
  4. Run the following command: firebase setup:emulators:pubsub. This will download the jar file.
  5. Try running the pubsub emulator again: firebase emulators:start --only pubsub

Possible related issue: https://github.com/firebase/firebase-tools-ui/issues/933

As soon as I downgraded to Node 16, it started working again

This started happening to me today (only on Bitrise CI tho). I removed pubsub from firebase.json (since I didn’t need it in my project anyway) and that “fixed” it.

Looks like @iSuslov might be right about something wrong with the unzipper

Error: Invalid or corrupt jarfile /Users/vagrant/.cache/firebase/emulators/pubsub-emulator-0.7.1/pubsub-emulator/lib/cloud-pubsub-emulator-0.7.1.jar

I had this issue until I downgraded Node from latest (19.x.x) to LTS (18.15.0).