gpt4 book ai didi

javascript - Firebase 函数 : Can not read property https of undefined

转载 作者:行者123 更新时间:2023-12-02 22:24:12 36 4
gpt4 key购买 nike

在终端中的 firebase 部署 期间,我在这一行收到错误:

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

最佳答案

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 代码正在导入未定义:

// 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(...)

一切顺利。我花了一段时间。

关于javascript - Firebase 函数 : Can not read property https of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59123832/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com