'NPM Run Script trying to run local file named "firebase.js" instead of using Firebase CLI

I have two scripts in a Create React App project that I would like to use when starting up the Firebase Emulator suite: em-startup and em-shutdown.

In package.json:

"em-startup": "firebase emulators:start --import=./data"

"em-shutdown": "firebase emulators:export ./data"

In my root project directory (singlethreddit) I can run the commands by typing them out explicitly, and they run without any problems. However, when I try running them by using their alias like npm run em-startup, I receive an error like the following:

enter image description here

I had not seen this error before and tried the following:

  1. Running npm install -g firebase-tools to ensure I was running the latest version of the Firebase CLI.
  2. Running npm install to ensure all of my other packages were up-to-date.

Since the message I received showed there was an issue with firebase.js it seemed that NPM was trying to run my firebase.js setup file which consists of the following:

import { initializeApp } from 'firebase/app';
import { getAnalytics } from "firebase/analytics";
import { connectAuthEmulator, getAuth } from 'firebase/auth';
import { connectFirestoreEmulator, getFirestore } from 'firebase/firestore';
import { connectStorageEmulator, getStorage } from 'firebase/storage';
import { fbConfig } from './firebase-config';

const app = initializeApp(fbConfig);
const analytics = getAnalytics(app);
const auth = getAuth(app);
const db = getFirestore(app);
const storage = getStorage(app);

if (window.location.hostname === 'localhost') {
    connectAuthEmulator(auth, 'localhost', 9099)
    connectFirestoreEmulator(db, 'localhost', 8080);
    connectStorageEmulator(storage, 'localhost', 9199);
}

export {
    db,
    storage,
}

And by changing the file name from firebase.js to firebase-setup.js the problem was resolved, but my question is: Why is NPM trying to run firebase.js in my root project directory rather than searching my node_modules folder for the firebase package?

I realize it is likely not a good practice to name local files after package files (will not do it again now that I have run into this problem) but I am curious why this is happening nonetheless.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source