klaviyo-api-node icon indicating copy to clipboard operation
klaviyo-api-node copied to clipboard

require() of ES Module \node_modules\klaviyo-api\node_modules\axios\index.js not supported

Open aen1gma opened this issue 1 year ago • 6 comments

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.

aen1gma avatar Jan 03 '24 06:01 aen1gma

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.

Ian-Montgomery-Klaviyo avatar Jan 03 '24 15:01 Ian-Montgomery-Klaviyo

Hi, I'm running Node v20.9.0 and I do not have the type property in my package.json

aen1gma avatar Jan 04 '24 05:01 aen1gma

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?

Ian-Montgomery-Klaviyo avatar Jan 04 '24 14:01 Ian-Montgomery-Klaviyo

Thanks, but I get exactly the same error regardless of whether I use import or require

aen1gma avatar Jan 08 '24 00:01 aen1gma

The team is looking into migrating to fetch, this should eliminate any issues caused by axios incompatibility.

Ian-Montgomery-Klaviyo avatar Aug 01 '24 18:08 Ian-Montgomery-Klaviyo