Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERR_REQUIRE_ESM error when starting emulator ui #1014

Open
wwmike opened this issue Feb 2, 2024 · 24 comments
Open

ERR_REQUIRE_ESM error when starting emulator ui #1014

wwmike opened this issue Feb 2, 2024 · 24 comments

Comments

@wwmike
Copy link

wwmike commented Feb 2, 2024

Describe the bug
When I start the emulators with emulators start command, all, but ui starts. This is the error log:

node:internal/modules/cjs/loader:1163
      throw err;
      ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/misi/.cache/firebase/emulators/ui-v1.11.7/server/server.js not supported.
server.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead rename server.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/misi/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Function.runMain (pkg/prelude/bootstrap.js:1979:12) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.5.0

I don't know where node v18.5.0 comes from, I haven't found this version on my PC, my node version is 21.1.0, which is available in $PATH. Also, once I could see v20 after nvm use v20... and deleting firebase cache, but the next run it was v18.5.0 again.

To Reproduce
Steps to reproduce the behavior:

  1. firebase emulators:start
  2. See error
~/projects/wish-list/frontend (WSH-17-calendar) $ firebase emulators:start    
i  emulators: Starting emulators: auth, firestore, database, storage
⚠  firestore: Cloud Firestore rules file /home/misi/projects/wish-list/frontend/firestore.rules specified in firebase.json does not exist.
⚠  firestore: The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.
i  firestore: downloading cloud-firestore-emulator-v1.18.2.jar...
Progress: ================================================================================================================================================================================> (100% of 64MB)
i  firestore: Firestore Emulator logging to firestore-debug.log
✔  firestore: Firestore Emulator UI websocket is running on 9150.
⚠  database: Did not find a Realtime Database rules file specified in a firebase.json config file. The emulator will default to allowing all reads and writes. Learn more about this option: https://firebase.google.com/docs/emulator-suite/install_and_configure#security_rules_configuration.
i  database: downloading firebase-database-emulator-v4.11.2.jar...
Progress: ================================================================================================================================================================================> (100% of 35MB)
i  database: Database Emulator logging to database-debug.log
i  storage: downloading cloud-storage-rules-runtime-v1.1.3.jar...
Progress: ================================================================================================================================================================================> (100% of 53MB)
i  ui: downloading ui-v1.11.7.zip...
Progress: =================================================================================================================================================================================> (100% of 4MB)
i  ui: Emulator UI logging to ui-debug.log
⚠  ui: Fatal error occurred: 
   Emulator UI has exited with code: 1, 
   stopping all running emulators
i  ui: Stopping Emulator UI
i  database: Stopping Database Emulator
i  firestore: Stopping Firestore Emulator
i  auth: Stopping Authentication Emulator
i  storage: Stopping Storage Emulator
i  hub: Stopping emulator hub
i  logging: Stopping Logging Emulator

Expected behavior
It should be running.

Desktop:

  • OS: Windows ( WSL 2.0 Ubuntu )
  • Browser -
  • Version Ubuntu 22.04.3 LTS

Additional context
Add any other context about the problem here.

@rynz
Copy link

rynz commented Mar 19, 2024

node:internal/modules/cjs/loader:986
    throw new ERR_REQUIRE_ESM(filename, true);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /home/ryan/.cache/firebase/emulators/ui-v1.11.8/server/server.mjs not supported.
Instead change the require of /home/ryan/.cache/firebase/emulators/ui-v1.11.8/server/server.mjs to a dynamic import() which is available in all CommonJS modules.
    at Function.runMain (pkg/prelude/bootstrap.js:1979:12) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.5.0

The same issue with a fresh install of Ubuntu 22.04.4 LTS. Tested Node 16, 18 and 20 LTS.
@christhompsongoogle Is Firebase Emulator not compatible with Ubuntu 22.04?

@christhompsongoogle
Copy link
Collaborator

I made some changes to the UI recently which changed the output from js to mjs - try installing a version prior to 13.5.1 and see if that fixes the issue

https://github.com/firebase/firebase-tools/releases/tag/v13.5.1

@rynz
Copy link

rynz commented Mar 20, 2024

try installing a version prior to 13.5.1 and see if that fixes the issue

https://github.com/firebase/firebase-tools/releases/tag/v13.5.0 fixes the issue.

@mosesgameli
Copy link

I have 13.6.0 and facing the same issue, should I downgrade?

@christhompsongoogle
Copy link
Collaborator

christhompsongoogle commented Mar 27, 2024 via email

@george-oakling
Copy link

Same here, downgrading to 13.5.0 solved the issue.

@jrdowns
Copy link

jrdowns commented May 3, 2024

Downgrading from 13.8.0 to 13.5.0 resolved the issue for me as well.

@apmorton
Copy link

apmorton commented Sep 8, 2024

running into this on macOS 14.6.1 as well:

firebase --version
13.16.0

and in ui-debug.log:

node:internal/modules/cjs/loader:986
    throw new ERR_REQUIRE_ESM(filename, true);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/amorton/.cache/firebase/emulators/ui-v1.13.0/server/server.mjs not supported.
Instead change the require of /Users/amorton/.cache/firebase/emulators/ui-v1.13.0/server/server.mjs to a dynamic import() which is available in all CommonJS modules.
    at Function.runMain (pkg/prelude/bootstrap.js:1979:12) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.5.0

Something is clearly broken here - and downgrading isn't really a solution - can someone please look at this?

@christhompsongoogle

@SakhileMamba
Copy link

SakhileMamba commented Sep 13, 2024

running into this on macOS 14.6.1 as well:

firebase --version
13.16.0

and in ui-debug.log:

node:internal/modules/cjs/loader:986
    throw new ERR_REQUIRE_ESM(filename, true);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/amorton/.cache/firebase/emulators/ui-v1.13.0/server/server.mjs not supported.
Instead change the require of /Users/amorton/.cache/firebase/emulators/ui-v1.13.0/server/server.mjs to a dynamic import() which is available in all CommonJS modules.
    at Function.runMain (pkg/prelude/bootstrap.js:1979:12) {
  code: 'ERR_REQUIRE_ESM'
}

Node.js v18.5.0

Something is clearly broken here - and downgrading isn't really a solution - can someone please look at this?

@christhompsongoogle

I have the exact problem. Did you manage to fix it.

@Genyus
Copy link

Genyus commented Sep 17, 2024

Something is clearly broken here - and downgrading isn't really a solution - can someone please look at this?

Same issue here, also on macOS 14.6.1.

firebase --version
13.17.0

Downgrading does work, but reports the following warnings:

npm install -g [email protected]
npm warn deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm warn deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm warn deprecated [email protected]: Package is no longer maintained
npm warn deprecated [email protected]: Package is no longer maintained
npm warn deprecated [email protected]: Package is no longer maintained

added 106 packages, removed 82 packages, and changed 551 packages in 6s

67 packages are looking for funding
  run `npm fund` for details

Additionally, this warning shows up in the function logs:

function[europe-west2-myFunction] (node:49542) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
function[europe-west2-myFunction] (Use `node --trace-deprecation ...` to show where the warning was created)

It would be great to see some movement on a proper fix as opposed to a risky workaround.

@k2bd
Copy link

k2bd commented Sep 22, 2024

I am also having this issue on Ubuntu 24.04.1 LTS | firebase 13.18.0

@kwight
Copy link

kwight commented Sep 23, 2024

At least on Mac, removing the broken curl-installed latest version (13.19.0) with curl -sL https://firebase.tools | uninstall=true bash and replacing it with the npm version (npm install -g firebase-tools@latest) works. ¯_(ツ)_/¯

@syt0r
Copy link

syt0r commented Sep 24, 2024

@kwight thanks, it fixed my error

@Genyus
Copy link

Genyus commented Oct 1, 2024

@kwight I didn't need to uninstall anything, but it appears that this issue is indeed fixed in 13.20.x 🥳

@neviaumi
Copy link

neviaumi commented Oct 1, 2024

@Genyus , i try get my firebase emulator on Docker work as code show below

FROM openjdk:24-slim

RUN apt-get update && apt-get install -y curl sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN curl -sL https://firebase.tools | bash

The same error present

node:internal/modules/cjs/loader:986
    throw new ERR_REQUIRE_ESM(filename, true);
    ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /root/.cache/firebase/emulators/ui-v1.13.0/server/server.mjs not supported.
Instead change the require of /root/.cache/firebase/emulators/ui-v1.13.0/server/server.mjs to a dynamic import() which is available in all CommonJS modules.
    at Function.runMain (pkg/prelude/bootstrap.js:1979:12) {
  code: 'ERR_REQUIRE_ESM'
}

Config:

root@3c8f7ba2d348:/# firebase --version
13.20.2
root@3c8f7ba2d348:/# node -v
v20.17.0

@Genyus
Copy link

Genyus commented Oct 2, 2024

@neviaumi Maybe try the approach suggested by @kwight above in your Docker config and install with npm instead of curl?

At least on Mac, removing the broken curl-installed latest version (13.19.0) with curl -sL https://firebase.tools | uninstall=true bash and replacing it with the npm version (npm install -g firebase-tools@latest) works. ¯_(ツ)_/¯

@neviaumi
Copy link

neviaumi commented Oct 2, 2024

@Genyus Thanks for suggestion :) I do fix it as you suggested. Using Npm instead of auto installation script.

Here is working docker file

FROM openjdk:24-slim

RUN apt-get update && apt-get install -y curl sudo
RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
RUN curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
RUN <<EOF
#!/bin/bash
source ~/.bashrc
nvm install --lts
nvm use --lts
npm install -g firebase-tools
EOF
RUN cat <<EOF > ./firebase.json
{
  "emulators": {
    "auth": {
      "host": "0.0.0.0"
    },
    "firestore": {
      "host":"0.0.0.0"
    },
    "ui": {
      "host": "0.0.0.0"
    }
  }
}
EOF
RUN mkdir -p ./scripts/docker
RUN cat <<EOF > ./scripts/docker/start.sh
#!/bin/bash
source ~/.bashrc
cat ./firebase.json
nvm use --lts
firebase emulators:start --project made-in-uk
EOF

@Zelfapp
Copy link

Zelfapp commented Oct 10, 2024

@kwight fixed mine as well on Ubuntu 22.04 with Firebase v13.22.0.

@RomuloPBenedetti
Copy link

This is making firebase-asdf unusable, unfortunately.

@mltsy
Copy link

mltsy commented Oct 19, 2024

I'm having the same issue on the latest version, 13.22.1, on MacOS, installed using the installation script from firebase.tools.

Installing via npm install -g firebase-tools as suggested by kwight gave me the same version (13.22.1), but the way that npm installed it, it works fine!

I wonder if it's something to do with the node environment it runs in, because I also noticed in ui-debug.log that when it was having an error, the end of the log said "Node.js v18.5.0" which is not a version I can find installed on my system... (at least not via nvm or asdf... I don't think MacOS has a system version of node preinstalled, does it?)

@patrickdundas
Copy link

Occurring for me on MacOS as well. Installing npm install -g firebase-tools did not fix the issue.

@mjrulesamrat
Copy link

Only thing that worked,

  1. Uninstall the latest firebase-tools (however you're installed. Just remove it.)
  2. Fix EACESS Permissions issues with https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
  3. Install firebase-tools using npm i firebase-tools@latest -g

In our case, we were not able to install firebase-tools using npm. The script version was getting installed, but it has some known bug with latest release.

@Rengoku-demon
Copy link

Rengoku-demon commented Nov 17, 2024

###ASAP -- i have a project submission next day please (Any one 🙏)
why is my app crashing in the emulator

@nikkieke
Copy link

Exact same issue here. @kwight thanks, your solution fixed it for me.
I'm using a mac.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests