由于依赖关系,Firebase函数构建失败



我刚刚用函数建立了一个新的firebase项目。

然后我添加了一个简单的触发功能,并想部署它

当我运行构建命令npm run build(tsc(时,我得到以下错误消息:

> functions@0.0.1 build {{PROJECT_PATH}}firebasefunctions
> 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 {

如何解决此问题?在我的代码中没有直接使用这些依赖项。

(例如,我将代码简化为一个函数,但错误没有改变(
我的函数代码:

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);

我在将firebase init完全清理到现有项目中时遇到了完全相同的问题。您看到的错误是node_modules中的@types/*错误。

这意味着您有以下选项:

快速且肮脏

tsconfig.json中,将"skipLibCheck": true添加到compilerOptions块:

{
"compilerOptions": {
// (...) firebase standard init
"skipLibCheck": true
},
// other stuff
}

艰难的道路

仔细阅读您的错误消息并安装丢失的@types/**软件包。在一个完全干净和新鲜的安装可以从以下开始:

  • @types/node
  • @types/express
  • (…(

只要留意这些线路../../../../../../../node_modules/@types/

相关内容

  • 没有找到相关文章