I get the following error when I run node index.js. I’ve tried several different solutions that I googled, but nothing is working. I included my index.js and package.json below the error.
internal/modules/cjs/loader.js:1089
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: c:\Users\lehi7\Blockchain\IvanTech\TradingBot\node_modules\node-fetch\src\index.js
require() of ES modules is not supported.
require() of c:\Users\lehi7\Blockchain\IvanTech\TradingBot\node_modules\node-fetch\src\index.js from c:\Users\lehi7\Blockchain\IvanTech\TradingBot\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 c:\Users\lehi7\Blockchain\IvanTech\TradingBot\node_modules\node-fetch\src\index.js to end in .cjs, change the requiring code to use import(), or remove “type”: “module” from c:\Users\lehi7\Blockchain\IvanTech\TradingBot\node_modules\node-fetch\package.json.
global.fetch = require("node-fetch");
const GeminiAPI = require("gemini-api").default;
const secret = "2qXyFFYLC000000000000";
const key = "account-lT0A1000000000000";
const CrypAPIKey = "6111310028358589af0a900000000000000000000";
const restClient = new GeminiAPI({ key, secret, sandbox: true });
const CryptoCompareAPI = require("cryptocompare");
CryptoCompareAPI.setApiKey(CrypAPIKey);
restClient.newOrder({ amount: 10, price: 1000, side: "buy",symbol: "ethusd" })
.then(response => console.log(response))
.catch(error => console.error(error));
CryptoCompareAPI.coinList()
.then(coinList => {
console.log(coinList)
})
/*restClient.getMyActiveOrders().then(response => console.log(response));*/
{
“name”: “tradingbot”,
“version”: “1.0.0”,
“description”: “crypto trading bot”,
“main”: “index.js”,
“scripts”: {
“test”: “echo “Error: no test specified” && exit 1”
},
“author”: “”,
“license”: “ISC”,
“dependencies”: {
“cryptocompare”: “^1.0.0”,
“gemini-api”: “^2.0.4”,
“node-fetch”: “^3.0.0”
}
}