@elastic/elasticsearch NPM库不能在mongodb领域功能中工作



我试图在mongodb领域功能集成@elastic/elasticsearch npm库。为了实现这个目标,我添加了@elastic/elasticsearch作为依赖项。

exports = async function(arg){
const { Client } = require('@elastic/elasticsearch');
try {
const apiKey = context.values.get("ES_API_KEY");
const cloudId = context.values.get("ES_CLOUD_ID");
const client = new Client({
cloud: {
id: cloudID
},
auth: {
apiKey
}
})
return client;

} catch(err) {
console.log("Error occurred while executing:", err.message);
return { error: err.message };
}

当我这样做时,我得到以下错误。

failed to execute source for 'node_modules/@elastic/elasticsearch/index.js': FunctionError: failed to execute source for 'node_modules/@elastic/transport/index.js': FunctionError: failed to execute source for 'node_modules/@elastic/transport/lib/connection/index.js': FunctionError: failed to execute source for 'node_modules/@elastic/transport/lib/connection/UndiciConnection.js': FunctionError: failed to execute source for 'node_modules/undici/index.js': FunctionError: failed to execute source for 'node_modules/undici/lib/api/index.js': FunctionError: failed to execute source for 'node_modules/undici/lib/api/api-request.js': FunctionError: Cannot find module 'async_hooks'

是什么导致这个问题?

似乎在这个时间点mongodb函数不支持最新的@elastic/elasticsearch版本8。

将版本降级到7.17.0已解决此问题。

相关内容

  • 没有找到相关文章