Hi,
I came across a failure when running following:
baichen@MacProM1:~/GeminiApi$ node index.js
node:internal/modules/cjs/loader:1125
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/baichen/GeminiApi/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.
require() of /Users/baichen/GeminiApi/node_modules/node-fetch/src/index.js from /Users/baichen/GeminiApi/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 /Users/baichen/GeminiApi/node_modules/node-fetch/src/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/baichen/GeminiApi/node_modules/node-fetch/package.json.
at new NodeError (node:internal/errors:363:5)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1125:13)
at Module.load (node:internal/modules/cjs/loader:988:32)
at Function.Module._load (node:internal/modules/cjs/loader:828:14)
at Module.require (node:internal/modules/cjs/loader:1012:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (/Users/baichen/GeminiApi/index.js:1:16)
at Module._compile (node:internal/modules/cjs/loader:1108:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1137:10)
at Module.load (node:internal/modules/cjs/loader:988:32) {
code: 'ERR_REQUIRE_ESM'
}
Code:
global.fetch = require("node-fetch");
const GeminiAPI = require("gemini-api").default;
const key = "xxxx";
const secret = "xxxx";
const CCAPIKey = "xxx";
const restClient = new GeminiAPI({key,secret,sandbox:true});
const CryptoCompareAPI = require("cryptocompare");
CryptoCompareAPI.setApiKey(CCAPIKey);