Skip to content

ESM import issue (replicated with Deno v2 and Node 23)Β #2466

@eturino

Description

@eturino

πŸ› Bug report

With v8.16.0 in a deno v2 project, we run into the following problem when running:

error: Could not resolve 'npm:@elastic/[email protected]'.

Caused by:
    [ERR_INVALID_PACKAGE_TARGET] Invalid "exports" main target {"require":"./index.js"} defined in the package config /workspaces/entities-api/node_modules/.deno/@[email protected]/node_modules/@elastic/elasticsearch/package.json imported from 'file:///workspaces/entities-api/src/search-api/es-client.ts'; target must start with "./"

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions