Issue occurred while trying to deploy Firebase functions following GTS initialization

Objective:

I am aiming to integrate Google's TypeScript style guide, gts, into my Firebase Functions project.

Desired Outcome:

I expect that executing the command firebase deploy --only functions will successfully deploy my functions even after initializing gts with npx gts init.

Actual Outcome:

Unfortunately, the deployment of my functions fails despite addressing several noticeable issues.

Steps to Replicate:

  1. Start the Firebase functions project by running firebase init functions within an empty directory.
  2. Add the relevant function code to the src/ directory.
  3. Execute either the "deploy" script or firebase deploy --only functions in the terminal.
    • Outcome: Functions are deployed without any complications.
  4. Run npx gts init in the functions/ directory to initialize gts.
  5. Execute either the "deploy" script or firebase deploy --only functions in the terminal.
    • Outcome: Deployment fails with the following error:
      • Error: There was an issue reading functions\package.json:
        functions\lib\index.js does not exist, preventing Cloud Functions deployment
  6. Rectify the directory mismatch.
    • Outcome: Deployment still fails with the same error.
  7. Correct the location of "main".
    • Outcome: Deployment fails again with the error message stating 'npm.cmd: not found'.
  8. Solve the 'npm.cmd: not found' error by removing '.cmd' from scripts.
    • Outcome: Deployment encounters a new error - tsc: not found

The structure and contents of important project files at various critical stages are outlined below.
Although detailed, I believe it is crucial to present potentially relevant information.

After initiating the Firebase functions project but before integrating gts:

The project adheres to the standard Firebase Functions layout.

my-project
 +- functions/     # Folder containing function code
      |
      +- lib/
      |   |
      |   +- index.js  # Transpiled JavaScript code
      |   |
      |   +- index.js.map # Source map for debugging
      |
      +- src/     # TypeScript source folder
      |   |
      |   +- index.ts  # Main source file for Cloud Functions 
      |
      +- .eslintrc.js # Optional ESLint file
      |
      +- package.json  # npm details for code
      |
      +- tsconfig.dev.json # Uses .eslintrc.js  
      |
      +- tsconfig.json

.eslintrc.js

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "plugin:import/errors",
    "plugin:import/warnings",
    "plugin:import/typescript",
    "google",
    "plugin:@typescript-eslint/recommended",
  ],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    project: ["tsconfig.json", "tsconfig.dev.json"],
    sourceType: "module",
  },
  ignorePatterns: [
    "/lib/**/*", // Excludes built files.
  ],
  plugins: [
    "@typescript-eslint","import"
  ],
  rules: {
    "quotes": ["error", "double"],
    "import/no-unresolved": 0,
    "indent": ["error", 2],
  },
};

package.json

{
  "name": "functions",
  "scripts": {
    "lint": "eslint --ext .js,.ts .",
    ...
  },
  "engines": {...},
  "main": "lib/index.js",
  "dependencies": {...},
  "devDependencies": {...},
  "private": true
}

tsconfig.dev.json

{
  "include": [
    ".eslintrc.js"
  ]
}

tsconfig.json

{
  "compilerOptions": {
    "module": "commonjs",
    ...
  },
  "compileOnSave": true,
  "include": [
    "src"
  ]
}

In this state, the "deploy" script completes successfully with no errors during the function deployment process.

(Continued) ...

Answer №1

I was able to reproduce the issue you mentioned. Below are the steps I took:

  1. Set up a new project in a clean folder called "FirebaseGTS" using the code snippet you provided
    "firebase init functions"
  2. Entered all the necessary information as required (e.g., existing project, Project ID)

Next

Selected Language: TypeScript

Opted not to use ESLint for bug detection and style enforcement: "NO"

The following files were automatically generated:

Wrote functions/package.json
Wrote functions/tsconfig.json
Wrote functions/src/index.ts
Wrote functions/.gitignore

Then

Chose to install dependencies with npm: YES to include all necessary packages.

  1. Ran firebase deploy --only functions

Outcome: Deployment completed successfully without any issues.

  1. Proceeded to install npx gts init within the function folder as per your instructions.

Generate Package.json if missing? : YES

"Auto generation process initiated"

Created package.json
Generated ./tsconfig.json
Added ./.eslintrc.json
Included ./.eslintignore
Configured ./.prettierrc.js
Set up ./.editorconfig

Result: Required packages added and audited as needed.

Note: Be cautious about overwriting devDependency considering v4.9.0 is now available instead of v4.7.0

  1. In the function directory, executed firebase deploy --only functions

Outcome: Successful deployment!

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Node C++ Addon Typescript declaration file

I have developed a Node C++ Addon that wraps a class similar to the one outlined in the official Node documentation. By using require(), I am able to access my addon and retrieve the constructor for my class in order to instantiate it. const { MyClass } = ...

An error is thrown when a try/catch block is placed inside a closure

An issue arises when attempting to compile this simple try/catch block within a closure using TypeScript: type TryCatchFn = (args: any, context: any) => void; function try_catch(fn: TryCatchFn): TryCatchFn { return (args, context) => void { ...

Using TypeScript, you can utilize RxJS to generate a fresh Observable named "Array" from a static array

I've successfully created an observable from an array, but the issue is that its type shows as Observable<number> instead of Observable<number[]> getUsers(ids: string[]): Observable<number[]> { const arraySource = Observable.from ...

Parsing temporary storage of database query results

My experience with OOP languages like C# and Java has been good, but I am relatively new to JavaScript/TypeScript. I find callback functions confusing, especially when using them with the BaaS ParseDB. For example, finding all playlists for a certain user ...

What could be causing the observable collection to display the correct number of objects, yet have them all appear empty?

I am offering the following service @Injectable() export class LMSVideoResulful { getVideos( enrolmentId : number ) :Observable<Array<Video>> { var x = new Array<Video>(); //https://www.youtube.com/embed/MV0vLcY65 ...

verifying the date in a specific moment

Is there a way to validate the date accurately? to determine whether she cleared it or not. I've exhausted all my options. Despite reading through the documentation, I am unable to get it right. Here is what I attempted: if ('2023-03-03 ...

"Exploring the Power of Firebase Analytics Debug Mode with BuddyBuild Integration

To activate Firebase Analytics Debug Mode, we must include the following flag: -FIRAnalyticsDebugEnabled This step is outlined in the official documentation. https://i.sstatic.net/WAr6z.png However... ... this method only functions when launching the ...

Issue encountered while deploying Firebase Functions: Unable to parse function triggers

Experiencing difficulty deploying firebase functions from an angular project after updating to the latest firebase-tools 7.8.1 version. The project's package.json contains "firebase-admin": "~6.0.0", "firebase-functions": "^2.1.0", and "firebase-funct ...

Creating a concise TypeScript declaration file for an established JavaScript library

I'm interested in utilizing the neat-csv library, however, I have encountered an issue with it not having a typescript definition file available. Various blogs suggest creating a basic definition file as a starting point: declare var neatCsv: any; M ...

The function res.send in Google Cloud is throwing an error

A scheduled Cron PubSub event triggers the function to retrieve data from an external API and update a Big Query table. During local testing (using the command npx @google-cloud/functions-framework --target pullElevate), the function operates as expected. ...

Flashing Screens with Ionic 2

I am currently dealing with a situation where my login page and homepage are involved. I have implemented native storage to set an item that helps in checking if the user is already logged in (either through Facebook or Google authentication). The logic fo ...

What could be causing my function to return as undefined the second time it's invoked?

Within my approach private onDataLoadSuccessful(users: User[], roles: Role[]) { this.alertService.stopLoadingMessage(); this.loadingIndicator = false; this.dataSource.data = users.map(data => { let newData: User; newData = ...

What is the process for upgrading TypeScript to the newest version using npm?

My current TypeScript version on my machine is 1.0.3.0 and I am looking to upgrade it to the latest version, which is 2.0. Could someone please guide me on how to accomplish this using npm? ...

Extracting data from a JSON object using Angular 2

I need advice on the most efficient way to handle JSON within my angular2 application. The JSON data I am working with includes: { "rightUpperLogoId": { "id": 100000, "value": "" }, "navbarBackgroundColorIdCss": { "id" ...

Issue: The TypeError reported is due to the absence of any definition for "_co.category.category_type"

I have two models: CategoryTypes and Categories. Each category type contains multiple categories. These are my two models. Categories Model import { Categories } from '../../categories/Mode/Categories' export class CategoryType { _id: strin ...

Why am I having trouble iterating through my array object?

Trying to showcase the contents of object within an array. However, unable to showcase any results. Why is this happening? This is what I've attempted so far: Demo available here: https://stackblitz.com/edit/ionic-dsdjvp?file=pages%2Fhome%2Fhome.ts ...

Enhancing AngularJS functionality through the integration of jQuery within a TypeScript module

As I try to integrate TypeScript into my codebase, a challenge arises. It seems that when loading jQuery and AngularJS in sequence, AngularJS can inherit functionalities from jQuery. However, when locally importing them in a module, AngularJS fails to exte ...

Vercel and Firebase Realtime Database causing snapshot.val() to return null during build deployment

Creating a blog application using Next.js, Firebase Realtime Database, and Vercel for hosting has been seamless on my local machine. Even after running npm run build, everything functions perfectly. However, when deployed to Netlify in production, the snap ...

Gain insights on Stripe Webhooks with Firebase Functions and Node.js

I've been struggling to integrate Firebase functions with Stripe webhooks for listening to events. Take a look at my code: exports.stripeEvents = functions.https.onRequest((request, response) => { try { const stripeSignature = request. ...

Unable to show the input's value

Need help in taking user input to display calculated values //html <div class="empty"> <h5> Enter Empty Seats </h5> <ion-item> <ion-input placeholder="Enter Number of Empties.." type="number" name="emptySeats" [( ...