getbrevo / brevo-node

A fully-featured JavaScript API client to interact with Brevo.
https://developers.brevo.com/
ISC License
52 stars 5 forks source link

Module not found: Can't resolve 'ApiClient' #4

Open Sokratesli opened 1 year ago

Sokratesli commented 1 year ago

I have a nextjs application and now i am trying to implement brevo. but it keeps showing me this error:

./node_modules/@getbrevo/brevo/src/index.js
Module not found: Can't resolve 'ApiClient'
Did you mean './ApiClient'?
Requests that should resolve in the current directory need to start with './'.
Requests that start with a name are treated as module requests and resolve within module directories.
If changing the source code is not an option there is also a resolve options called 'preferRelative' which tries to resolve these kind of requests in the current directory too.

https://nextjs.org/docs/messages/module-not-found

Thanks for the help.

Reproduce:

  1. yarn create next-app xyz (noTS, yesESLint, yesTailwind, noSrc-Folder, yesAppRouter, noImportAlias)
  2. yarn add @getbrevo/brevo
  3. importinging custom send-email.js (below) code in page.js import SendEmail from ./send-email
  4. yarn dev (error message above)

send-email.js


const Brevo = require("@getbrevo/brevo");

export function SendEmail(
  subject,
  senderName,
  message,
  senderEmail,
  recipientEmail,
  recipientName
) {
  if (
    !subject ||
    !senderName ||
    !message ||
    !senderEmail ||
    !recipientEmail ||
    !recipientName
  ) {
    const error = new Error("notAllRequiredValues");
    return Promise.reject(error);
  }

  const defaultClient = Brevo.ApiClient.instance;

  const apiKey = defaultClient.authentications["api-key"];
  apiKey.apiKey = process.env.BREVO_API;

  const partnerKey = defaultClient.authentications["partner-key"];
  partnerKey.apiKey = process.env.BREVO_API;

  const api = new Brevo.AccountApi();
  return new Promise((resolve, reject) => {
    api.getAccount().then(
      function (data) {
        console.log("API called successfully. Returned data: " + data);
        resolve(data);
      },
      function (error) {
        console.error(error);
        reject(error);
      }
    );
  });
}
shivpratik commented 1 year ago

Even I'm getting the same error.

shubhamUpadhyayInBlue commented 1 year ago

Hi @Sokratesli @shivpratik Can you please share with me the steps to reproduce it?

MichalKarchutPapaya commented 1 year ago

Hi @shubhamUpadhyayInBlue have the same issue even though I have installed brevo package and followed the steps written in Readme about instalation I have problem with connect API image

Ange0 commented 1 year ago

"I am also facing this problem - error ./node_modules/@getbrevo/brevo/src/index.js Module not found: Can't resolve 'ApiClient' Did you mean './ApiClient'? Requests that should resolve in the current directory need to start with './'. Requests that start with a name are treated as module requests and resolve within module directories (node_modules, /Users/angelo/Documents/APP_DEV/nextjs/gestyon-stok). If changing the source code is not an option, there is also a resolve option called 'preferRelative' which tries to resolve these types of requests in the current directory too."

Ange0 commented 1 year ago

The problem seems to be that the tool I'm using to compile my Next.js code (https://swc.rs/) supports AMD modules. However, in the brevo-node documentation, specifically in the "Webpack Configuration" section

Capture d’écran 2023-07-05 à 10 24 30

, it specifies to disable AMD modules. Therefore, the simplest solution is to use their API without any additional installation using fetch, for example. In my case, I'm using:

Capture d’écran 2023-07-05 à 10 34 42

I want to clarify that I'm using the node-fetch package (https://www.npmjs.com/package/node-fetch) on the server side.

shivpratik commented 1 year ago

Hi @Sokratesli @shivpratik Can you please share with me the steps to reproduce it?

Hi @shubhamUpadhyayInBlue, I'm getting this error when trying to import "@getbrevo/brevo" in files apart from the main API file. Example: I wanted to have all my email and sms functions in a separate file and when I try to import "@getbrevo/brevo" in that file I get this error. This error doesn't occur when used in API handler file.

Charlygraphy23 commented 1 year ago

When i install @getbrevo/brevo from npm it's working as expected in my vite react app and node app. but not able to run the package from local for react project. In my case the issue didn't occurs. Can you share the steps to reproduce.

SiM07 commented 1 year ago

Same issue here. The project used sib before and after upgrade to @getbrevo/brevo.

shubhamUpadhyayInBlue commented 1 month ago

Hello, It's because the dependencies are not installed correctly. Running an npm install fixed it. Screenshot 2024-08-13 at 2 24 03 PM