Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
aen1gma opened this issue Jan 3, 2024 · 5 comments

Comments

@aen1gma
Copy link

aen1gma commented Jan 3, 2024

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.

@Ian-Montgomery-Klaviyo
Copy link
Collaborator

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.

@aen1gma
Copy link
Author

aen1gma commented Jan 4, 2024

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

@Ian-Montgomery-Klaviyo
Copy link
Collaborator

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?

@aen1gma
Copy link
Author

aen1gma commented Jan 8, 2024

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

@Ian-Montgomery-Klaviyo
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants