Deploying Firebase functions results in an error

Just recently started exploring Firebase functions. Managed to install it on my computer, but running into an error when trying to execute:

=== Deploying to 'app'...
i  deploying firestore, functions
Running command: npm --prefix "$RESOURCE_DIR" run lint

> functions@ lint /Users/username/Documents/appdevelopment/app/functions
> eslint --ext .js,.ts .

/Users/username/Documents/appdevelopment/app/functions/index.js
0:0  error  Parsing error: "parserOptions.project" has been set for @typescript- 
eslint/parser.
The file does not match your project config: index.js.
The file must be included in at least one of the projects provided

/Users/username/Documents/appdevelopment/app/functions/src/index.ts
1:13  warning  'functions' is defined but never used  @typescript-eslint/no-unused- 
vars

✖ 2 problems (1 error, 1 warning)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint --ext .js,.ts .`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely additional logging 
output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/username/.npm/_logs/2021-08-15T21_08_19_284Z-debug.log

Error: functions predeploy error: Command terminated with non-zero exit code1

The issue seems to indicate that a required file is missing and mentions a function being defined but unused. Did I overlook something during the installation process?

Here are the commands I used for installing Firebase functions:

  • npm install
  • npm install -g firebase-tools
  • firebase login
  • firebase init firestore
  • firebase init functions I performed all these within the folder structure: Documents/appdevelopment/app/

This snippet shows my test function setup:

   const functions = require("firebase-functions");
   const admin     = require('firebase-admin');
   const db        = admin.firestore();

   admin.initializeApp();

   exports.vote = functions.firestore
   .document('Votes/{vote}')
   .onCreate((document, context) => {
    const row       = document.data()['id'];
    const vote      = document.data()['vote'];

    if (vote == 1) {
        const field = '1star';
    } else if (vote == 2) {
        const field = '2star';
    } else if (vote == 3) {
        const field = '3star';
    } else if (vote == 4) {
        const field = '4star';
    } else {
        const field = '5star';
    }

    const incremento = firebase.firestore.FieldValue.increment(1);
    const incrementv = firebase.firestore.FieldValue.increment(1);

    db.doc('message/'+row).set({field: incremento, 'votes': incrementv})


});

Upon running firebase deploy, the aforementioned error occurs.

----- edit----

After adding an index.js and an index.ts file (not sure which language defaulted) under functions/src/, the error message changed to:

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

> functions@ lint 
 /Users/username/Documents/appdevelopment/app/functions
> eslint --ext .js,.ts .

/Users/username/Documents/appdevelopment/
app/functions/src/index.js
0:0  error  Parsing error: "parserOptions.project" has been set 
for @typescript-eslint/parser.
The file does not match your project config: src/index.js.
The file must be included in at least one of the projects provided

✖ 1 problem (1 error, 0 warnings)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! functions@ lint: `eslint --ext .js,.ts .`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the functions@ lint script.
npm ERR! This is probably not a problem with npm. There is likely   
logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/username/.npm/_logs/2021-08- 
16T08_27_58_329Z-debug.log

Error: functions predeploy error: Command terminated with non- 
zero exit code1

Answer №1

When working with TypeScript tools in Cloud Function for Firebase, the recommended practice is to store your Cloud Functions code in a file named index.ts within the myproject/functions/src directory by default. As stated in the official documentation, this file is crucial because it gets transpiled to index.js during firebase deployment.

If you have an existing Cloud Functions project that was originally developed in JavaScript, fret not! You can easily migrate it to TypeScript following the comprehensive steps outlined in this helpful tutorial. Just remember to create a backup before proceeding with the migration process.

Answer №2

Hooray! Successfully resolved the problem by relocating index.ts from functions/ to functions/src/. All set for deploying my functions now.

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

Looking to incorporate ipcRenderer from Electron into your Angular project? Having trouble accessing variables passed from the preload script?

I am struggling with incorporating ipcRenderer into the 'frontend' code of my electron app. Although I found examples in the documentation that use require, this method is not accessible on the frontend side where I am utilizing Angular. In the ...

Securing your Angular application with user authentication and route guarding ensures

In the process of developing an Angular single-page application (SPA) front-end that interacts with a GraphQL endpoint, I encountered a challenge. Upon user login, I store the token in local storage and update the authentication state in my AuthService com ...

npm encountered an issue in identifying the executable to execute while trying to run the command npx cap sync

Whenever I execute npx cap sync, the following error is displayed: npm ERR! could not determine executable to run I have searched for answers on multiple platforms, but none seem to address this issue in relation to capacitor. This problem started arising ...

Ways to input a return value that may be an array depending on the input

I'm struggling to properly type the return value in TypeScript to clear an error. function simplifiedFn( ids: string | string[], ): typeof ids extends string[] ? number[] : number { const idsIsArray = Array.isArray(ids); const idsProvided = idsI ...

Creating autorest client based on various OpenAPI versions

I'm currently exploring options for creating a Typescript client from our .NET API. After researching various tools, I decided to go with Autorest, as it is Node-based and fits my skillset. While I am aware of Swashbuckle, my knowledge leans more towa ...

Issue with npm configuration permissions

I am encountering permission issues when using the npm config command. It appears that there is an attempt to alter the owner of my ~/.npmrc file without authorization. Upon executing npm config set color false, I encounter the following error: npm ERR! E ...

How can Karma unit tests with Jasmine in a TypeScript Node project accurately measure code coverage, even with external dependencies?

We have a unique situation with the code coverage of our project involving a node dependency. It's important to note that the npm dependency source code is actually part of our project, as we are responsible for its development and publication. Here&a ...

The FileReader's onload event handler does not seem to be triggering as expected

In short, my issue revolves around reading a csv file from an android device using JavaScript's FileReader. Although my code was functioning properly a month ago, upon revisiting it recently I discovered that the onload function no longer seems to be ...

React: Material UI causing an error due to an invalid hook call

Working on a React project using create-react-app with material UI, encountering errors like: https://i.stack.imgur.com/mhjkE.png Appears to be an internal issue with material UI once setting a custom theme. import { ThemeProvider } from "@mui/material/ ...

Utilizing custom hooks for passing props in React Typescript

I have created a unique useToggler custom hook, and I am attempting to pass toggle props from it to the button child in the Header component. However, when I try using toggle={toggle}, I encounter this error: Type '{toggle: () => void;}' is ...

Unable to execute node modules that are installed globally

Having trouble with my Mac OS 10.8.5 finding globally installed modules by npm. I'm attempting to run bbb from the command line, but keep getting an error: $ bbb -bash: bbb: command not found I've checked that it's installed correct ...

Dealing with typescript error due to snakecase attributes being sent from the database while the frontend only accepts pascalcase attributes

I am facing a challenge regarding converting snake case values from my api to pascal case attributes in the front end. Here is the scenario: Frontend Request Axios request fetching multiple user data, for example: axios.get('/users') API Resp ...

What is preventing the terminal from recognizing that I have successfully updated to the newest version of tar?

Struggling to get the react app installed using this code: sudo npm i -g <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="107362757164753d62757173643d71606050213e253e22">[email protected]</a> Continuously facing t ...

There seems to be an issue with the React Native FlatList: It appears that there is no overload matching this call and some

I am currently learning React Native and attempting to create a basic chat room application. I am facing an issue with the FlatList component that I can't seem to resolve. Even though I have provided both the data prop and renderItem prop to the FlatL ...

Unable to retrieve information from firebase due to the following issue: TypeError: Unable to access properties of undefined (reading 'map')

When trying to display data on my post page from Firebase, I encountered the following error: TypeError: Cannot read properties of undefined (reading 'map') Below is my Feed.js where I fetch all the data from Firebase. import { SparklesIcon } ...

What is the best way to incorporate cors modules in TypeScript?

I am encountering some difficulties while attempting to import the cors module in a TypeScript project using Express. When I use the following code: import cors from "cors"; I receive the following error message: "Cannot find module &apos ...

Discovering React Styled Components Within the DOM

While working on a project using Styled Components in React, I have successfully created a component as shown below: export const Screen = styled.div({ display: "flex", }); When implementing this component in my render code, it looks like this ...

What could be causing the error "Type 'String' cannot be used as an index type" to appear in my TypeScript code?

My JavaScript code contains several associative arrays for fast object access, but I'm struggling to port it to TypeScript. It's clear that my understanding of TypeScript needs improvement. I've searched for solutions and come across sugges ...

Publishing on Npm necessitated my presence being logged in despite the fact that I was already logged in

I've been encountering some issues with deploying my npm package. Initially, I deployed it manually by running 'npm publish' and everything went smoothly, with the package being successfully published. However, I wanted the package to be aut ...

Is there a point in bundling NPM packages if they are ultimately going to be bundled by the project

I'm in the process of creating a TypeScript package for publication on NPM. My plan is to utilize this package in upcoming web development endeavors, most likely utilizing Vite. As I look ahead to constructing a future website with this module, I am c ...