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

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

Open
Sokratesli opened this issue Jun 22, 2023 · 10 comments
Open

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

Sokratesli opened this issue Jun 22, 2023 · 10 comments

Comments

@Sokratesli
Copy link

Sokratesli commented Jun 22, 2023

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
Copy link

Even I'm getting the same error.

@shubhamUpadhyayInBlue
Copy link
Collaborator

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

@MichalKarchutPapaya
Copy link

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
Copy link

Ange0 commented Jul 4, 2023

"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
Copy link

Ange0 commented Jul 5, 2023

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
Copy link

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
Copy link

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
Copy link

SiM07 commented Sep 18, 2023

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

@shubhamUpadhyayInBlue
Copy link
Collaborator

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

@InnoVa74
Copy link

Same problem can't resolve 'ApiClient'. I tried "npm install" but nothing...

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

8 participants