【问题标题】:MongoDb can't use types in jest - declares ... locally, but it is not exportedMongoDb 不能在玩笑中使用类型 - 在本地声明 ...,但不会导出
【发布时间】:2022-04-19 16:02:30
【问题描述】:

我将 TypeScript 中的 mongodb 库用于一些函数(例如 lambda 函数,但这不重要)。

导入看起来像这样:

import { ObjectId, Db, InsertOneResult } from "mongodb";

当我在 Jest 中导入函数并执行它时,我总是得到错误:

Module '"../../node_modules/mongodb/mongodb.ts34"' declares 'ObjectId' locally, but it is not exported.

我认为我的笑话逻辑有问题,但我不确定是什么。该函数本身正在运行。

我的笑话配置如下:

const tsPreset = require("ts-jest/jest-preset");

module.exports = {
  ...tsPreset,
  testEnvironment: "node",
  roots: ["<rootDir>/test"],
  testMatch: ["**/*.test.ts"],
  moduleNameMapper: {
    "^@/types/(.*)$": "<rootDir>/types/$1",
    "^@/lib/(.*)$": "<rootDir>/lib/$1",
    "^@/functions/(.*)$": "<rootDir>/functions/$1",
  },
};

【问题讨论】:

    标签: node.js typescript mongodb jestjs


    【解决方案1】:

    这似乎与this ticket 有关。当前版本的 mongodb 节点驱动不再兼容 typescript 3.9。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-05
      • 2020-06-29
      • 2020-06-11
      • 2018-05-15
      • 2018-07-16
      • 2021-06-20
      • 1970-01-01
      相关资源
      最近更新 更多