NPM运行脚本试图运行名为“ firebase.js”的本地文件。而不是使用Firebase CLI
我在创建Firebase Emulator Suite时想使用的Create React App项目中有两个脚本:em-startup
和em-shutdown
。
在package.json
中:
“ em-startup”:“ firebase仿真器:start -import =。/data”
“ em-shutdown”: :export ./data“
在我的root项目目录(singlethreddit
)中,我可以通过明确键入命令来运行命令,并且它们运行没有任何问题。但是,当我尝试通过使用它们的别名(例如npm运行em-startup
)运行它们时,我会收到以下错误:
我以前从未见过此错误,并且尝试过以下内容:
- 运行
npm install -G firebase -tools
,以确保我运行了最新版本的Firebase CLI。 - 运行
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:
I had not seen this error before and tried the following:
- Running
npm install -g firebase-tools
to ensure I was running the latest version of the Firebase CLI. - 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论