0
votes

I already have a Firebase functions that are currently working fine. These functions were deployed when I was using Windows machine. Today I thought to modify something in the functions with my Mac machine. When I am trying to reinitialize the same project, the index.js comes with the default code without my functions that I deployed.

Following are the steps I am performing in order to reinitialize the project.

  • firebae init
  • Select: Functions: Configure and deploy Cloud Functions
  • Use an existing project
  • I am selecting my project name
  • language: JavaScript
  • Do you want to use ESLint to catch probable bugs and enforce style? Yes
  • Do you want to install dependencies with npm now? (Y/n) Yes

Now, when I go and check the index.js in the function folder it has only one default code.

const functions = require('firebase-functions');

However, I can see the functions with my custom code at https://console.cloud.google.com/functions.

please help. Thanks for your time and help

2

2 Answers

3
votes

Initializing a project with the Firebase CLI doesn't not rebuild any source code that you might have previously deployed. You should be storing that in some sort of source control, such as git, in order to share it between people, projects, and machines. If you don't use source control, you will have to manually copy the files between machines.

0
votes

You can just re-run firebase init functions to regenerate the firebase config (not download your source code)

I had to reinitialize my firebase functions (title of the question) because I was getting some errors in firebase-debug.log about firebase.json. I deleted it and wanted to regenerate it. I didn't have the issue the question poster had (I guess he literally ran firebase init and expected the code to be transferred from his windows computer to his mac, which is why Doug said "you will have to manually copy the files between machines".)


I was getting the error, Error: Not in a Firebase app directory (could not locate firebase.json). I ran firebase init functions in the root directory of the project which already had a functions directory, and the error was fixed.

The following showed up:

=== Functions Setup

A functions directory will be created in your project with sample code
pre-configured. Functions can be deployed with firebase deploy.

? What language would you like to use to write Cloud Functions? TypeScript
? Do you want to use ESLint to catch probable bugs and enforce style? Yes
? File functions/package.json already exists. Overwrite? No
i  Skipping write of functions/package.json
? File functions/.eslintrc.js already exists. Overwrite? No
i  Skipping write of functions/.eslintrc.js
? File functions/tsconfig.json already exists. Overwrite? No
i  Skipping write of functions/tsconfig.json
? File functions/tsconfig.dev.json already exists. Overwrite? No
i  Skipping write of functions/tsconfig.dev.json
? File functions/src/index.ts already exists. Overwrite? No
i  Skipping write of functions/src/index.ts
? File functions/.gitignore already exists. Overwrite? No
i  Skipping write of functions/.gitignore
? Do you want to install dependencies with npm now? Yes