NPM运行脚本试图运行名为“ firebase.js”的本地文件。而不是使用Firebase CLI

发布于 2025-01-28 22:39:11 字数 1944 浏览 5 评论 0原文

我在创建Firebase Emulator Suite时想使用的Create React App项目中有两个脚本:em-startupem-shutdown

package.json中:

“ em-startup”:“ firebase仿真器:start -import =。/data”

“ em-shutdown”: :export ./data“

在我的root项目目录(singlethreddit)中,我可以通过明确键入命令来运行命令,并且它们运行没有任何问题。但是,当我尝试通过使用它们的别名(例如npm运行em-startup)运行它们时,我会收到以下错误:

”

我以前从未见过此错误,并且尝试过以下内容:

  1. 运行npm install -G firebase -tools,以确保我运行了最新版本的Firebase CLI。
  2. 运行npm install以确保我所有其他软件包都是最新的。

由于我收到的消息显示firebase.js似乎有一个问题,因此NPM似乎试图运行我的firebase.js设置文件,该文件由以下内容组成

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,
}

:从firebase.js更改文件名为firebase-setup.js问题已经解决,但我的问题是:为什么NPM试图运行firebase.js在我的root项目目录中而不是搜索我的node_modules firebase软件包的文件夹?

我意识到,在软件包文件之后命名本地文件可能不是一个好习惯(现在我遇到了这个问题,我不会再做一次),但是我很好奇为什么这会发生这种情况。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文