Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
liu-xiao-guo opened this issue Jul 10, 2024 · 0 comments
Open

Comments

@liu-xiao-guo
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant