Firebase functions build fails due to dependencies

Viewed 178

I just set up a new firebase project with functions.

Then I added a simple trigger function and wanted to deploy it.

When I run the build command npm run build (tsc) I get the following error message:

> functions@0.0.1 build {{PROJECT_PATH}}\firebase\functions
> tsc

../../../../../../../node_modules/@types/express-serve-static-core/index.d.ts:504:18 - error TS2430: Interface 'Response<ResBody, StatusCode>' incorrectly extends interface 'ServerResponse'.
  Types of property 'req' are incompatible.
    Type 'Request<ParamsDictionary, any, any, ParsedQs> | undefined' is not assignable to type 'IncomingMessage'.
      Type 'undefined' is not assignable to type 'IncomingMessage'.

504 export interface Response<ResBody = any, StatusCode extends number = number> extends http.ServerResponse, Express.Response {
                     ~~~~~~~~

../../../../../../../node_modules/@types/readable-stream/index.d.ts:19:15 - error TS2417: Class static side 'typeof _Readable' incorrectly extends base class static side 'typeof Readable'.
  The types of 'Stream.Readable.Duplex' are incompatible between these types.
    Property 'isDisturbed' is missing in type 'typeof _Readable.Duplex' but required in type 'typeof import("stream").Duplex'.

19 declare class _Readable extends stream.Readable {
                 ~~~~~~~~~

  node_modules/@types/node/stream.d.ts:59:20
    59             static isDisturbed(stream: Readable | NodeJS.ReadableStream): boolean;
                          ~~~~~~~~~~~
    'isDisturbed' is declared here.

../../../../../../../node_modules/@types/readable-stream/index.d.ts:68:11 - error TS2720: Class 'Duplex' incorrectly implements class '_Readable'. Did you mean to extend '_Readable' and inherit its members as a subclass?
  Type 'Duplex' is missing the following properties from type '_Readable': readableAborted, readableDidRead

68     class Duplex extends Writable implements /*extends*/_Readable, stream.Duplex {
             ~~~~~~

../../../../../../../node_modules/@types/readable-stream/index.d.ts:68:11 - error TS2720: Class '_Readable.Duplex' incorrectly implements class 'import("stream").Duplex'. Did you mean to extend 'import("stream").Duplex' and inherit its members as a subclass?
  Type 'Duplex' is missing the following properties from type 'Duplex': readableAborted, readableDidRead

68     class Duplex extends Writable implements /*extends*/_Readable, stream.Duplex {
             ~~~~~~

../../../../../../../node_modules/@types/readable-stream/index.d.ts:111:11 - error TS2720: Class '_Readable.PassThrough' incorrectly implements class 'import("stream").PassThrough'. Did you mean to extend 'import("stream").PassThrough' and inherit its members as a subclass?
  Type 'PassThrough' is missing the following properties from type 'PassThrough': readableAborted, readableDidRead

111     class PassThrough extends Transform implements stream.PassThrough {
              ~~~~~~~~~~~

../../../../../../../node_modules/@types/readable-stream/index.d.ts:173:11 - error TS2720: Class '_Readable.Transform' incorrectly implements class 'import("stream").Transform'. Did you mean to extend 'import("stream").Transform' and inherit its members as a subclass?
  Type 'Transform' is missing the following properties from type 'Transform': readableAborted, readableDidRead

173     class Transform extends Duplex implements stream.Transform {

How can I resolve this issues? None of this dependencies are used directly in my code.

(For the example I reduced my code to a single function but the error did not change)
My Functions code:

index.ts
export {
  authUserCreatedTrigger
} from './user/auth-user.trigger';



config.ts
export const functionsRegion = 'europe-west1';
export const firestoreSettings = {timestampsInSnapshots: true};
export enum FirebaseCollection {
  User = 'user',
}



auth-user.trigger.ts
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

const firestore = admin.firestore();
firestore.settings(firestoreSettings);


const onCreateHandler = async (user: admin.auth.UserRecord, context: functions.EventContext) => {
  // Email is an required field
  if (!user.email) {
    return null;
  }

  // Disable user on default
  user = await admin.auth().updateUser(user.uid, {
    disabled: true,
  });

  // Split up user object
  const {uid, displayName, photoURL, email, phoneNumber, disabled} = user;

  // Get firestore user document ref
  const userDocumentRef = firestore.collection(FirebaseCollection.User).doc(uid);

  // Write new user to firestore
  return userDocumentRef.set({
    uid,
    displayName,
    photoURL,
    email,
    emailVerified: false,
    phoneNumber,
    disabled,
    deletedAt: null,
    createdAt: admin.firestore.Timestamp.now(),
  });
};

export const authUserCreatedTrigger = functions
    .region(functionsRegion)
    .auth
    .user()
    .onCreate(onCreateHandler);

1 Answers

I had the exact same issue with a complete clean firebase init into an existing project. The errors you are seeing are @types/* errors within node_modules.

Which means that you have the following options:

The quick and dirty

in your tsconfig.json add "skipLibCheck": true to your compilerOptions block:

{
  "compilerOptions": {
    // (...) firebase standard init

    "skipLibCheck": true
  },
  // other stuff
}

The hard way

read through your error messages and install the missing @types/** packages. In a complete clean and fresh install can start with the following:

  • @types/node
  • @types/express
  • (...)

Just keep an eye at these lines ../../../../../../../node_modules/@types/

Related