Skip to content

Commit d0f5ada

Browse files
authored
[Backport 8.16] Fix ECMAScript import (#2477)
1 parent 47de886 commit d0f5ada

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed

.github/workflows/nodejs.yml

+9-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
strategy:
3333
fail-fast: false
3434
matrix:
35-
node-version: [18.x, 20.x, 22.x]
35+
node-version: [18.x, 20.x, 22.x, 23.x]
3636
os: [ubuntu-latest, windows-latest, macOS-latest]
3737

3838
steps:
@@ -57,6 +57,10 @@ jobs:
5757
run: |
5858
npm run test:unit
5959
60+
- name: ECMAScript module test
61+
run: |
62+
npm run test:esm
63+
6064
license:
6165
name: License check
6266
runs-on: ubuntu-latest
@@ -111,6 +115,10 @@ jobs:
111115
run: |
112116
bun run test:unit-bun
113117
118+
- name: ECMAScript module test
119+
run: |
120+
bun run test:esm
121+
114122
auto-approve:
115123
name: Auto-approve
116124
needs: [test, license]

package.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,15 @@
66
"main": "./index.js",
77
"types": "index.d.ts",
88
"exports": {
9-
"require": "./index.js"
9+
"require": "./index.js",
10+
"import": "./index.js",
11+
"types": "./index.d.ts"
1012
},
1113
"scripts": {
1214
"test": "npm run build && npm run lint && tap",
1315
"test:unit": "npm run build && tap",
1416
"test:unit-bun": "bun run build && bunx tap",
17+
"test:esm": "npm run build && cd test/esm/ && npm install && node test-import.mjs",
1518
"test:coverage-100": "npm run build && tap --coverage --100",
1619
"test:coverage-report": "npm run build && tap --coverage && nyc report --reporter=text-lcov > coverage.lcov",
1720
"test:coverage-ui": "npm run build && tap --coverage --coverage-report=html",

test/esm/package.json

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"name": "esm",
3+
"version": "1.0.0",
4+
"dependencies": {
5+
"@elastic/elasticsearch": "file:../.."
6+
}
7+
}

test/esm/test-import.mjs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Licensed to Elasticsearch B.V. under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch B.V. licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
import { Client } from '@elastic/elasticsearch'
21+
22+
new Client({
23+
node: 'http://localhost:9200',
24+
auth: {
25+
username: 'elastic',
26+
password: 'changeme',
27+
}
28+
})

0 commit comments

Comments
 (0)