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.<anonymous> (/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
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:
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: