elastic / elastic/docs

Error [ERR_REQUIRE_ESM]: require() of ES Module "xxxx" is not suppored

Open
#3,030 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Ruby
Stars
265
Forks
347
Avg merge
3d 15h
Merged PRs (30d)
2

Description

I followed the instructions at https://www.elastic.co/guide/en/cloud/current/ec-getting-started-search-use-cases-node-logs.html t create a webrequests.js file. When I run the script, and I have the following error:

```
$ node webrequests.js
/Users/liuxg/nodejs/nodejs-logs/webrequests.js:315
undefined
^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/liuxg/nodejs/node_modules/got/dist/source/index.js from /Users/liuxg/nodejs/nodejs-logs/webrequests.js not supported.
Instead change the require of index.js in /Users/liuxg/nodejs/nodejs-logs/webrequests.js to a dynamic import() which is available in all CommonJS modules.
at TracingChannel.traceSync (node:diagnostics_channel:315:14)
at Object. (/Users/liuxg/nodejs/nodejs-logs/webrequests.js:1:13) {
code: 'ERR_REQUIRE_ESM'
}

Node.js v22.4.1
```

It seems that Got depends on diffrent versions, and it usage is also different. It would be good to speifiy its Node.js and Got package versions. Also, it can be worked around with the following code:

`import got from 'got';`

However, we need to rename the script extension to .mjs. I am using the following versions:

```
$ node -v
v22.4.1
$ npm -v got
10.8.1
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.