require() of ES Module \node_modules\klaviyo-api\node_modules\axios\index.js not supported
After installing 7.2.0 and adding the import statement - import { ApiKeySession, ProfileCreateQuery, ProfileEnum, ProfilesApi } from 'klaviyo-api', I get the following error in the compiler...
Error [ERR_REQUIRE_ESM]: require() of ES Module <my_server>\node_modules\klaviyo-api\node_modules\axios\index.js not supported. Instead change the require of index.js in null to a dynamic import() which is available in all CommonJS modules.
To help recreate this issue could you provide the node version you are using and the type property from your package.json if applicable.
We will try and recreate the issue and find a workaround and/or make a patch.
Hi, I'm running Node v20.9.0 and I do not have the type property in my package.json
Sounds like a commonJS import issue, Try changing how you are importing the KlaviyoApi to use require.
Here is an expressJS example of making an api call while using commonJS imports
var express = require('express');
const KlaviyoApi = require('klaviyo-api')
var router = express.Router();
/* GET home page. */
router.get('/', async function(req, res, next) {
const session = new KlaviyoApi.ApiKeySession(`YOUR API KEY HERE`)
const profilesApi = new KlaviyoApi.ProfilesApi(session)
const response = await profilesApi.getProfiles()
res.send(response.body)
});
module.exports = router;
Does that fix your issue?
Thanks, but I get exactly the same error regardless of whether I use import or require
The team is looking into migrating to fetch, this should eliminate any issues caused by axios incompatibility.