运行 firebase Deploy -Flutter -Firebase 时在错误的路径中生成 Functions 文件夹

Posted

技术标签:

【中文标题】运行 firebase Deploy -Flutter -Firebase 时在错误的路径中生成 Functions 文件夹【英文标题】:Functions folder is generated in the wrong path when running firebase Deploy -Flutter -Firebase 【发布时间】:2020-12-04 07:46:14 【问题描述】:

我是使用 Firebase 函数的新手,我正在尝试为 Firebase 设置函数,以便为我的应用中的常见活动设置通知,但我正在遵循 firebase 建议的步骤(见下文) Function 文件夹在错误的路径中生成(见下文),firebase 函数屏幕仍然要求设置。

Function 文件夹应该是在我的项目文件夹中创建的,我该如何解决这个问题?

1:$ npm install -g firebase-tools 2:$ firebase init 3:$ firebase deploy

C:\Users\BAQ-229\androidStudioProjects\reviu\Functions>firebase init

     ######## #### ########  ######## ########     ###     ######  ########
     ##        ##  ##     ## ##       ##     ##  ##   ##  ##       ##
     ######    ##  ########  ######   ########  #########  ######  ######
     ##        ##  ##    ##  ##       ##     ## ##     ##       ## ##
     ##       #### ##     ## ######## ########  ##     ##  ######  ########

You're about to initialize a Firebase project in this directory:

  C:\Users\BAQ-229

Before we get started, keep in mind:

  * You are initializing in an existing Firebase project directory

? Are you ready to proceed? Yes
? Which Firebase CLI features do you want to set up for this folder? Press Space to select features, then Enter to confirm your choices. Functions: Configure and deploy Cloud Functions

=== Project Setup

First, let's associate this project directory with a Firebase project.
You can create multiple project aliases by running firebase use --add,
but for now we'll just set up a default project.

i  .firebaserc already has a default project, using jobly-b45bf.

=== Functions Setup

A functions directory will be created in your project with a Node.js
package pre-configured. Functions can be deployed with firebase deploy.

? What language would you like to use to write Cloud Functions? javascript
? Do you want to use ESLint to catch probable bugs and enforce style? Yes
+  Wrote functions/package.json
+  Wrote functions/.eslintrc.json
+  Wrote functions/index.js
+  Wrote functions/.gitignore
? Do you want to install dependencies with npm now? Yes

> protobufjs@6.10.1 postinstall C:\Users\BAQ-229\functions\node_modules\protobufjs
> node scripts/postinstall

npm notice created a lockfile as package-lock.json. You should commit this file.
added 361 packages from 266 contributors and audited 361 packages in 12.507s

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

found 0 vulnerabilities


i  Writing configuration info to firebase.json...
i  Writing project information to .firebaserc...

+  Firebase initialization complete!

C:\Users\BAQ-229\AndroidStudioProjects\reviu\Functions>firebase deploy

=== Deploying to 'jobly-b45bf'...

i  deploying functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint C:\Users\BAQ-229\functions
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
+  functions: required API cloudbuild.googleapis.com is enabled
+  functions: required API cloudfunctions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...

+  Deploy complete!

Project Console: https://console.firebase.google.com/project/jobly-b45bf/overview

【问题讨论】:

路径错误是什么意思?您希望它在哪里以及它是在哪里创建的? 我希望它在我的项目文件中使用以下路径创建:C:\Users\BAQ-229\AndroidStudioProjects\reviu 【参考方案1】:

通过查看控制台的输出,您将位于 Functions 文件夹中。在您的主项目文件夹(C:\Users\BAQ-229\AndroidStudioProjects\reviu)上上一层并从那里运行命令,完成后,它将创建一个名为 functions 的新文件夹,其中的骨架您的 Cloud Functions 将驻留

更新:您之前似乎在 C:\Users\BAQ-229 上创建了一个 firestore 项目,以避免在此目录中创建结构:

    在您的 C:\Users\BAQ-229 目录或其下的任何其他子目录中找到并删除 firebase.json 文件 再次运行 C:\Users\BAQ-229\AndroidStudioProjects\reviu\ 目录中的firebase init 命令(我认为这是您的主项目文件夹)

【讨论】:

已经这样做了,但它正在 C:\Users\BAQ-229 中创建 Functions 文件夹 这个答案解决了我的问题,我必须删除我的 C:\Users\BAQ-229 中的 firebase.json 文件,然后在 C:\Users\BAQ-229 中再次运行 Firebase init \AndroidStudioProjects\reviu\ 目录,非常感谢! 太好了,如果答案解决了您的问题,请随时接受答案,以便社区从中受益

以上是关于运行 firebase Deploy -Flutter -Firebase 时在错误的路径中生成 Functions 文件夹的主要内容,如果未能解决你的问题,请参考以下文章

Firebase Github Deploy无法解析travis.yml

firebase deploy 在颤振应用程序中出现错误

firebase deploy --only 函数上出现 NPM 错误的原因是啥

firebase deploy --only hosting 给出错误:HTTP 错误:410,未知错误

为啥 export const helloWorld 在 firebase deploy 中出现错误而 export.helloWorld 没有?

Node.js 应用程序的 firebase deploy 命令导致错误:`runtime` field is required but was not found in firebase.json