firebase / firebase-tools-ui

A local-first UI for Firebase Emulator Suite.
https://firebase.googleblog.com/2020/05/local-firebase-emulator-ui.html
Apache License 2.0
261 stars 60 forks source link

ERR_REQUIRE_ESM error when starting emulator ui #1014

Open wwmike opened 5 months ago

wwmike commented 5 months ago

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:

Additional context Add any other context about the problem here.

rynz commented 3 months ago
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 commented 3 months ago

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 commented 3 months ago

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 commented 3 months ago

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

christhompsongoogle commented 3 months ago

Try downgrading and report the results, I can't reproduce on my linux version but more information is helpful

On Wed, Mar 27, 2024 at 2:09 PM Moses Gameli @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/firebase/firebase-tools-ui/issues/1014#issuecomment-2023995002, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZKGOHSY3YILS6HWXBXOBJLY2MYRZAVCNFSM6AAAAABCWHS7PCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMRTHE4TKMBQGI . You are receiving this because you were mentioned.Message ID: <firebase/firebase-tools-ui/issues/1014/2023995002 <(202)%20399-5002>@ github.com>

george-oakling commented 2 months ago

Same here, downgrading to 13.5.0 solved the issue.

jrdowns commented 2 months ago

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