elasticsearch-js-mock icon indicating copy to clipboard operation
elasticsearch-js-mock copied to clipboard

TypeError: Cannot destructure property 'ConfigurationError' of 'errors' as it is undefined.

Open jlarroque opened this issue 5 years ago • 6 comments

Hi folks, I'm trying to use this library but I'm seeing the following error. Am I doing something wrong?

TypeError: Cannot destructure property 'ConfigurationError' of 'errors' as it is undefined. image

Some additional info: "@elastic/elasticsearch-mock": "^0.3.0" "@elastic/elasticsearch": "^7.8.1"

jlarroque avatar Nov 04 '20 13:11 jlarroque

Hello! I just tried to reproduce this issue by using the example in the README and the latest version of both libraries and I didn't see any issue. Is this still happening to you?

delvedor avatar Dec 10 '20 12:12 delvedor

I just experienced this. It seems specifically typescript related. If I run the example.js file locally, it runs perfectly fine. If I try to import Mock from '@elastic/elasticsearch-mock'; in any typescript file, I get the above error. I'm using "typescript": "^4.1.3"

Hiteklife avatar Feb 10 '21 06:02 Hiteklife

I also get the same error when using typescript

covertbert avatar Apr 28 '21 13:04 covertbert

I am experiencing the same issue. Someone has some update?

DaniloOliveira28 avatar Oct 12 '21 12:10 DaniloOliveira28

You can reproduce the error if you create the mock with this dir structure

__mocks__ |_@elastic     |_elasticsearch.ts

import Client from '@elastic/elasticsearch';
import Mock from '@elastic/elasticsearch-mock';

const mock = new Mock()
const client = new Client({
 node: 'http://localhost:9200',
 Connection: mock.getConnection()
})

mock.add({
 method: 'GET',
 path: '/_cat/health'
}, () => {
 return { status: 'ok' }
})

client.cat.health(console.log)

DaniloOliveira28 avatar Oct 12 '21 12:10 DaniloOliveira28

I've had this issue to and ended up solving by mocking it like this:

jest.mock('./client', () => ({
  getClient: () => mockedClient,
}))

too-soon avatar Apr 09 '23 22:04 too-soon