iampavangandhi / Gitwar

🚀 Gitwar - Compete with Github ( ⚠️ NOT ACTIVELY MAINTAINED )
https://gitwar.up.railway.app
MIT License
122 stars 21 forks source link

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

Open jishanshaikh4 opened 2 years ago

jishanshaikh4 commented 2 years ago

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!