Jest 无法从“client.js”中找到模块“pg-native”

Tia*_*bia 7 postgresql node.js knex.js jestjs objection.js

我的项目由 node (express)、knex、objectionjs 和 graphql 组成。我们正在使用 Jest 来测试对 graphql 的调用,它在后台使用 objectionjs+knex 在 Postgres 数据库上执行更新。

任何调用更新具有 JSON 字段的表的开玩笑测试都会在控制台中给出错误:

console.error node_modules/pg/lib/index.js:52 无法从“client.js”中找到模块“pg-native”

However, Jest was able to find:
    './client.js'

You might want to include a file extension in your import, or update your 'moduleFileExtensions', which is currently ['js', 'json', 'jsx', 'ts', 'tsx', 'node'].

See https://jestjs.io/docs/en/configuration#modulefileextensions-array-string
Run Code Online (Sandbox Code Playgroud)

无论如何测试都完成了,但这是我想摆脱的烦恼。

有没有人遇到过这个问题?让我知道我可以提供哪些额外的代码细节来帮助诊断问题。

更新: 使用本文中建议的解决方法设法使消息消失:https : //github.com/sequelize/sequelize/issues/3781#issuecomment-522198459

小智 0

在所有文件中查找:

const { connect } = require('pg/lib/native');
Run Code Online (Sandbox Code Playgroud)

并删除