I am having exactly the same problem, I read all the answers above and below, and I ll be keeping a track on this issue. Unfortunatly, I cannot advance on the course until someone can help us solve this.
Here is my console log and code:
algotrading> node index.js
internal/modules/cjs/loader.js:1102
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: Z:\A-IVANONTECH ACADEMY\algotrading\node_modules\node-fetch\src\index.js
require() of ES modules is not supported.
require() of Z:\A-IVANONTECH ACADEMY\algotrading\node_modules\node-fetch\src\index.js from Z:\A-IVANONTECH ACADEMY\algotrading\index.js is an ES module file as it is a .js file whose nearest parent package.json contains “type”: “module” which defines all .js files in that package scope as ES modules.
Instead rename Z:\A-IVANONTECH ACADEMY\algotrading\node_modules\node-fetch\src\index.js to end in .cjs, change the requiring code to use import(), or remove “type”: “module” from Z:\A-IVANONTECH ACADEMY\algotrading\node_modules\node-fetch\package.json.
←[90m at Object.Module._extensions…js (internal/modules/cjs/loader.js:1102:13)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:950:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:790:14)←[39m
←[90m at Module.require (internal/modules/cjs/loader.js:974:19)←[39m
←[90m at require (internal/modules/cjs/helpers.js:92:18)←[39m
at Object. (Z:\A-IVANONTECH ACADEMY\algotrading\index.js:1:16)
←[90m at Module._compile (internal/modules/cjs/loader.js:1085:14)←[39m
←[90m at Object.Module._extensions…js (internal/modules/cjs/loader.js:1114:10)←[39m
←[90m at Module.load (internal/modules/cjs/loader.js:950:32)←[39m
←[90m at Function.Module._load (internal/modules/cjs/loader.js:790:14)←[39m {
code: ←[32m’ERR_REQUIRE_ESM’←[39m
}
global.fetch = require(“node-fetch”);
//Conection to the TESTING gemini platform
const GeminiAPI = require(“gemini-api”).default;
//These are just TESTING NOT REAL MONEY NOR WALLET KEYS
const secret = “XXX”;
const key = “XXX”;
//This is a free api from crypto compare
const CrypAPIKey = “XXX”;
const restClient = new GeminiAPI({key, secret, sandbox:true});
const CryptoCompareAPI = require(“cryptocompare”);
CryptoCompareAPI.setApiKey(CrypAPIKey);
restClient.newOrder({amount:10, price:100, side:“buy”, symbol:“btcusd”})
.then(response => console.log(response))
.catch(error => console.log(error));
CryptoCompareAPI.coinList()
.then(coinList => {
console.log(coinList)
})
(ON MY CODE XXX IS REPLACED BY THE REAL KEYS OF COURSE)
I thank you in advance for any reply or assistance to whoever could give us a clue