firebase 火力基地功能:无法读取未定义的属性https

ddhy6vgd  于 2023-02-25  发布在  其他
关注(0)|答案(3)|浏览(92)

firebase deploy in terminal期间,我在这一行中得到一个错误:

// index.js in the output folder
const firebase_functions_1 = __importDefault(require("firebase-functions"));

exports.buyUsedServer = firebase_functions_1.default.https.onRequest(express);

// index.ts in the source folder
import firebaseFunctions from 'firebase-functions';

export const buyUsedServer = firebaseFunctions.https.onRequest(express);
//# sourceMappingURL=index.js.map

是什么firebaseFunctions(或默认对象)导致了这里的问题?
以下是完整堆栈跟踪:

i  functions: preparing functions directory for uploading...

Error: Error occurred while parsing your function triggers.

TypeError: Cannot read property 'https' of undefined
    at Object.<anonymous> (/home/owner/PhpstormProjects/shopify/project/functions/outDir/index.js:170:54)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:785:10)
    at Module.load (internal/modules/cjs/loader.js:641:32)
    at Function.Module._load (internal/modules/cjs/loader.js:556:12)
    at Module.require (internal/modules/cjs/loader.js:681:19)
    at require (internal/modules/cjs/helpers.js:16:16)
    at /home/owner/.nvm/versions/node/v12.4.0/lib/node_modules/firebase-tools/lib/triggerParser.js:15:15
    at Object.<anonymous> (/home/owner/.nvm/versions/node/v12.4.0/lib/node_modules/firebase-tools/lib/triggerParser.js:53:3)
    at Module._compile (internal/modules/cjs/loader.js:774:30)
r9f1avp5

r9f1avp51#

和您一样,我想使用这个ES6导入而不是CommonJS(require())。

import { https } from 'firebase-functions';

我从here得到了这个答案,它有更多的信息。

dgtucam1

dgtucam12#

您应该执行以下操作:
首先导入模块firebase-functions

// The Cloud Functions for Firebase SDK to create Cloud Functions and setup triggers.
const functions = require('firebase-functions');

然后,您可以调用onRequest()

exports.date = functions.https.onRequest((req, res) => {
  // ...
});

您可以查看文档here.

eufgjt7s

eufgjt7s3#

TLDR:我所做的只是改变:

import functions from 'firebase-functions'

收件人:

import * as functions from 'firebase-functions`

说明:我在用

import functions from 'firebase-functions'

从TS到JS后,我的JS文件看起来像这样:

const firebase_functions_1 = __importDefault(require("firebase-functions"));

JS正在尝试导入从firebase-functions导出的default模块。问题是,当我查看node_modules/firebase-functions/lib/v1/index. d. ts时(将来可能会更改),它没有任何默认导出,因此我的JS代码正在导入undefined

// node_modules/firebase-functions/lib/v1/index.d.ts
import * as logger from "../logger";
import * as analytics from "./providers/analytics";
import * as auth from "./providers/auth";
import * as database from "./providers/database";
import * as firestore from "./providers/firestore";
import * as https from "./providers/https";
import * as pubsub from "./providers/pubsub";
import * as remoteConfig from "./providers/remoteConfig";
import * as storage from "./providers/storage";
import * as tasks from "./providers/tasks";
import * as testLab from "./providers/testLab";
import { setApp as setEmulatedAdminApp } from "../common/app";
export { analytics, auth, database, firestore, https, pubsub, remoteConfig, storage, tasks, testLab, logger, };
export declare const app: {
    setEmulatedAdminApp: typeof setEmulatedAdminApp;
};
export * from "./cloud-functions";
export * from "./config";
export * from "./function-builder";
export * from "./function-configuration";

我所做的只是改变:

import functions from 'firebase-functions'

收件人:

import * as functions from 'firebase-functions`

或者只导入https模块:

import { https } from 'firebase-functions'

const helloWorld = https.onCall(...)

你可以走了。花了我点时间。

相关问题