Error encountered in Firebase cloud functions code due to a life cycle issue

Encountering an error when attempting to deploy the initial code provided by firebase init for cloud functions and calling firebase deploy. The source code within index.ts remains unmodified, just like the rest of the project.

Running command: npm --prefix "$RESOURCE_DIR" run build

> functions@ build /Users/eliasdolinsek/development/firebase-development/functions
> tsc

../../../node_modules/@types/fs-extra/index.d.ts:195:87 - error TS2694: Namespace '"fs"' does not have an exported member 'Dir'.

195 export function opendir(path: string, cb: (err: NodeJS.ErrnoException | null, dir: fs.Dir) => void): void;
                                                                                          ~~~

../../../node_modules/@types/fs-extra/index.d.ts:198:17 - error TS2694: Namespace '"fs"' does not have an exported member 'OpenDirOptions'.

198 options: fs.OpenDirOptions,
                    ~~~~~~~~~~~~~~

../../../node_modules/@types/fs-extra/index.d.ts:199:53 - error TS2694: Namespace '"fs"' does not have an exported member 'Dir'.

199 cb: (err: NodeJS.ErrnoException | null, dir: fs.Dir) => void,
                                                        ~~~

../../../node_modules/@types/fs-extra/index.d.ts:201:52 - error TS2694: Namespace '"fs"' does not have an exported member 'OpenDirOptions'.

201 export function opendir(path: string, options?: fs.OpenDirOptions): Promise<fs.Dir>;
                                                       ~~~~~~~~~~~~~~

../../../node_modules/@types/fs-extra/index.d.ts:201:80 - error TS2694: Namespace '"fs"' does not have an exported member 'Dir'.

201 export function opendir(path: string, options?: fs.OpenDirOptions): Promise<fs.Dir>;
                                                                                   ~~~


Found 5 errors.

npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! functions@ build: `tsc`
npm ERR! Exit status 2
npm ERR! 
npm ERR! Failed at the functions@ build script.
npm ERR! This is likely not a problem with npm. Additional logging output may be present above.

npm ERR! A detailed log of this run can be found in:
npm ERR!     /Users/eliasdolinsek/.npm/_logs/2021-01-26T13_18_50_649Z-debug.log

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

Answer №1

Make sure to include the typeRoots property in your tsconfig.json located within the functions directory

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017",
    "typeRoots": [
      "./functions/node_modules/@types"
    ],
  },
  "compileOnSave": true,
  "include": [
    "src"
  ],
}

Visit this Github thread for more information

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

Angular Relationships (Error 400 - Invalid Request)

I am encountering a significant issue when trying to add data to a table connected with the Spring database. The problem arises specifically when I attempt to add new data to the table, but encounter errors when choosing options from a Combo Box. This is t ...

Guide for utilizing a sitemap in Firebase hosting for a React application

I recently launched a reactjs web application on firebase hosting. To ensure better indexing by search engines, I created a sitemap.xml file and placed it in the public folder. Then, I made changes to my firebase.json file to redirect the source to the sit ...

How can one access DOM elements (getting and setting values) that are nested within an *ngFor loop?

How can I access the <span> and <select> elements in my code template shown below? <div *ngFor="---"> <div> <span></span> <select> <option></option> <option></option> ...

I'm looking to convert this typescript function to return an array with strong typing instead of just a plain string[]

I am currently in the process of converting a JavaScript function to TypeScript. Originally, I believed that the type of the variable hi would be ('s'|'bb')[], but it turned out to be string[]. Is there a way for TypeScript to automatic ...

Encountered Typescript issue when utilizing typed forms in Angular

Below is the interface I am working with: export interface ILoginDto { email: string; password: string; } Here is a snippet of the relevant code from the component: import { FormBuilder, FormGroup, Validators } from '@angular/forms'; export ...

Discovering a discrepancy in Angular’s documentation: when using a template reference variable, it does not

One thing that has caught my attention in the Angular Documentation is an example related to Angular template input variables. I tested this code snippet myself, hoping that the text entered in the input box would appear next to it as mentioned in the docu ...

What methods can be implemented to ensure ComponentOverride's universality?

These type definitions for markdown-to-jsx don't seem to be generic enough, causing issues like the one mentioned below. For more details, refer to Why is type SFC<AnchorProps> not assignable to type SFC<{}>? /Users/sunknudsen/Sites/sunk ...

Struggling to successfully deploy an Angular application on Azure

I'm currently in the process of deploying my Angular app to Azure. Utilizing VS Code and the "Azure App Service" extension. I have diligently followed this guide step by step: Upon completing the guide, I was successful in deploying the Angular app ...

Is there a way I can keep my ChartJS constantly updated in real time? Currently, it only seems to update when I zoom in or out

I'm looking to create a dynamic graph that updates every 5 seconds or in real-time. I've managed to get it working when zooming in and out of the page, but not when doing nothing. I know it's possible to achieve this, but I can't seem t ...

Effortlessly apply mapping, filtering, reducing, and more in JavaScript

Array#map and Array#filter both create a new array, effectively iterating over the original array each time. In languages like rust, python, java, c#, etc., such expression chains only iterate once, making them more efficient in certain cases. While this ...

When ngIf evaluates to false, Angular4's ng-content is constructed

I'm facing an issue with the new ng-content transclusion feature. To illustrate, let's consider a scenario where I have a component called my-component that performs some intensive operations in its ngOnInit() function (for now, just a console.l ...

"Is there a way to dynamically remap an array only when there are changes

One of the challenges I am facing is with a component called Page, which contains two components - Editor and Preview. Page has an array called items. [ { value: 0, text: 'Item 1' }, ... ] This array items is passed ...

Issues arise when trying to insert a control based on the index in an Angular Reactive FormArray

Below is the form structure I am working with: this.addForm = this.formBuilder.group({ details: this.formBuilder.array([]), }); To add a new control, I use the following function: nestedFormGroupDetails(control) { control.push( this.f ...

Organizing Data Using JSON and Firebase

I understand the process of creating and retrieving data using Firebase, but I am unsure about the best way to reference different users. On their website, they provide an example of saving user data that results in a JSON tree structure like this: { "u ...

Enhance your FullCalendar experience with React by displaying extra information on your calendar

I am new to using React and FullCalendar, and I have a page layout similar to the image linked below. https://i.sstatic.net/MooTR.png Additionally, I have a list of events structured as shown: id: "9", eventId: "1", ...

A guide to accessing Firebase push notification content and triggering a method in Ionic 2

Can Ionic 2 allow access to push notification content and trigger a set of actions when notifications arrive or events are fired? ...

Simple steps to turn off error highlighting for TypeScript code in Visual Studio Code

Hey there! I've encountered an issue with vscode where it highlights valid code in red when using the union operator '??' or optional chaining '?.'. The code still builds without errors, but vscode displays a hover error message st ...

encountering difficulties calling setAttribute within a function

I am encountering an issue while attempting to use setAttribute() within toggleDiv(). My IDE does not seem to recognize the function and is throwing an error. How can I resolve this problem so that the function is recognized? This specific case relates t ...

What is the best way to identify property errors in a React/Typescript project using ESLint?

I'm currently in the process of transitioning a Typescript project created with create-react-app to the latest version. As part of this update, I am moving from tslint to eslint which has posed some challenges. The main issue I'm facing is gettin ...

What is the best method for keeping two properties in a Typescript object in sync in a flexible manner?

I am looking to illustrate the concept that a property of an object is "in sync" with another property within the same object. Consider a hypothetical type called Widget, which represents a UI component storing a specific data type. type Widget = { id: ...