首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法从'node_modules/firebase-functions-test/lib/providers/firestore.js‘中找到模块“firebase- find /lib/编码器”

无法从'node_modules/firebase-functions-test/lib/providers/firestore.js‘中找到模块“firebase- find /lib/编码器”
EN

Stack Overflow用户
提问于 2022-05-21 20:18:36
回答 1查看 560关注 0票数 0

嘿,我正试着在这里测试这个云功能:

代码语言:javascript
复制
import { logger, region, https } from "firebase-functions/v1";
import Message from "../types/message";

const helloWorldHandler = region("europe-west1").https.onCall((_, context) => {
  if (context.app == undefined) {
    throw new https.HttpsError("failed-precondition", "The function must be called from an App Check verified app.");
  }

  logger.info("Hello logs!", { structuredData: true });
  const message: Message = {
    text: "Hello from Firebase!",
    code: 200,
  };
  return message;
});

export default helloWorldHandler;

通过以下测试:

代码语言:javascript
复制
import * as functions from "firebase-functions-test";
import * as path from "path";

const projectConfig = {
  projectId: "myproject-id",
};

const testEnv = functions(projectConfig, path.resolve("./flowus-app-dev-fb-admin-sdk-key"));
// has to be after initializing functions
import helloWorldHandler from "../src/functions/helloworld";
import Message from "../src/types/message";

describe('Testing "helloWorld"', () => {
  const helloWorld = testEnv.wrap(helloWorldHandler);

  it("helloWorld does work", async () => {
    const data = {};

    const success: Message = await helloWorld(data);
    expect(success.code).toBe(200);
  });
});

当我使用yarn test运行它时,我会收到以下错误Cannot find module 'firebase-functions/lib/encoder' from 'node_modules/firebase-functions-test/lib/providers/firestore.js',即使我的函数一开始甚至没有使用过防火墙?

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2022-05-26 09:46:24

当我试图为防火墙云功能建立一个单元测试环境时,我也面临着一个类似的问题。主要是,在遵循[医][火基地]文档上的所有步骤并运行npm test之后,我将得到以下错误

错误的ERR_PACKAGE_PATH_NOT_EXPORTED包子路径‘./lib/编码器’不是由“导出”定义的

在被法里德对这个问题的建议绊倒后,我意识到,由于某种原因,npm i firebase-functions-test没有安装该模块的最新版本。

试试npm i firebase-functions-test@latest

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72332941

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档