Closed eturino closed 1 week ago
This is not just Deno. Just happened on Node 23 as well for me. The new *.16 release is broken.
I expected so, but I only tried it in deno.
@JoshMock I am mentioning you here, as I believe you'd be interested in knowing that the latest version doesn't work at all. It can't even be imported.
This is crazy, how not a single javascript user can use elastic right now, this should be a urgent issue!!!!!!!
So it's really a bug? Any workaround on this?
Just down grade to 7.16.10 or whatever the prior major version was and that will fix issue for now.
@eturino You can refer to this PR #2467 for a temporary solution, or downgrade to a version before 8.16.0.
[commonjs--resolver] Failed to resolve entry for package "@elastic/elasticsearch".
The package may have incorrect main/module/exports specified in its package.json:
No known conditions for "." specifier in "@elastic/elasticsearch" package transforming (51) ../index.ts
A quick turnaround would be greatly appreciated.
I think @ajkraus04 advice is wrong: the issue comes from 8.16.0
not from 8.x
. And 7.x
clients are not compatible with 8.x
clusters.
So before 8.16.x
is fixed, depending on the version of your cluster you should set the package version to 8.15.2
instead ("@elastic/elasticsearch": "8.15.2"
in package.json
)
This yarn add @elastic/elasticsearch@8.15.2
solves the following error
import { ErrorCause } from "@elastic/elasticsearch/lib/api/types";
error TS2307: Cannot find module '@elastic/elasticsearch/lib/api/types' or its corresponding type declarations.
16 import { ErrorCause } from "@elastic/elasticsearch/lib/api/types";
We need types
entry for TypeScript as well:
{
"exports": {
".": {
"types": "./index.d.ts",
"default": "./index.js"
}
}
}
Thanks for your patience, everyone. I've opened https://github.com/elastic/elasticsearch-js/pull/2475 with a fix, as well as a smoke test to ensure ECMAScript imports continue to work going forward. I will publish a patch release 8.16.1 today with the fix.
This was only was broken for 8.16.0, so downgrading to 8.15.x is a temporary fix. It was also only broken for code using native ECMAScript import
syntax, so the client was working as expected for those still using CommonJS require
syntax.
@JoshMock I'm still noticing weird behaviours on 8.16.1, the following fails despite working on 8.15 and previous releases.
import type {
SearchRequest,
SearchResponse
} from '@elastic/elasticsearch/lib/api/types';
Specifically it fails with TS2307: Cannot find module '@elastic/elasticsearch/lib/api/types' or its corresponding type declarations.
@augustozanellato lib/api/types
seems not intended to be used outside the package. You can use estypes
barrel export instead:
import type {estypes} from '@elastic/elasticsearch';
let req: estypes.SearchRequest;
@augustozanellato
lib/api/types
seems not intended to be used outside the package. You can useestypes
barrel export instead:import type {estypes} from '@elastic/elasticsearch';
let req: estypes.SearchRequest;
That indeed solved my issue, thanks.
Yep, estypes
is the best way to handle it for now. I do want to ensure maximum flexibility, though, so I'll look into adding exports for more files.
🐛 Bug report
With v8.16.0 in a deno v2 project, we run into the following problem when running:
For what I can see, the issue is in the
exports
section of the package.json. Probably should be"exports": { ".": "./index.js" },
(replace "require" with ".")The issue is not present with 8.15.x versions, which are commonjs packages entirely.
To reproduce
In a deno v2 (potentially also other ESM runtimes), install version 8.16.0 and run your app and/or any tests that uses a file that imports the es library.
Expected behavior
Should be imported and run as expected
Node.js version
Deno v2
@elastic/elasticsearch version
8.16.0
Operating system
Debian bookworm
Any other relevant environment information
No response