Skip to content

node-fetch incompatibility with latest CommonJS modules' require() #32

@jishanshaikh4

Description

@jishanshaikh4

Latest node-fetch is only compatible with ESM modules. Reverting to old node-fetch would work as long as other vulnerable spots are covered.

Error:

> gitwar@1.0.2 start
> node app.js

Gitwar/utils/fetchTrending.js:2
const fetch = require("node-fetch");
              ^

Error [ERR_REQUIRE_ESM]: require() of ES Module /Gitwar/node_modules/node-fetch/src/index.js from /Gitwar/utils/fetchTrending.js not supported.
Instead change the require of index.js in /Gitwar/utils/fetchTrending.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (/Gitwar/utils/fetchTrending.js:2:15)
    at Object.<anonymous> (/Gitwar/routes/top.js:6:31)
    at Object.<anonymous> (/Gitwar/app.js:40:19) {
  code: 'ERR_REQUIRE_ESM'
}

Reverting to older version of node-fetch should do the job!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions