Skip to content

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

Open

Description

@liu-xiao-guo

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions