sendinblue / APIv3-nodejs-library

SendinBlue's API v3 Node.js Library
ISC License
101 stars 47 forks source link

Module not found: Can't resolve 'ApiClient' in ...\node_modules\sib-api-v3-sdk\src' #101

Closed EricHasegawa closed 1 year ago

EricHasegawa commented 3 years ago

Following the basic instructions, after running npm install sib-api-v3-sdk --save and then pasting in `var SibApiV3Sdk = require('sib-api-v3-sdk');

var defaultClient = SibApiV3Sdk.ApiClient.instance;` I get the error mentioned in the title. It seems to me like this is an error within the API, but I could also be doing something wrong. Does anyone have any suggestions?

shubhamUpadhyayInBlue commented 3 years ago

Hey @EricHasegawa I tried to replicate the error that you are facing but could not do it with the following steps:

  1. Added these lines to a file: var SibApiV3Sdk = require('sib-api-v3-sdk'); var defaultClient = SibApiV3Sdk.ApiClient.instance;
  2. Then run this on terminal: npm install sib-api-v3-sdk --save
  3. The package.json looks like this: { "name": "testwrappers", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": {}, "devDependencies": { "sib-api-v3-sdk": "^8.2.0" } }

It looks like the dependencies were not correctly installed. Can you please try to remove the node_modules folder and then install the dependencies again? Do let me know if you face any issues.

IrfDev commented 3 years ago

Same issue here, I already try installing modules again!

Carter-Phillips commented 3 years ago

Having this same issue, using yarn to install the package, then importing with import SibAPI from 'sib-api=v3-sdk'. It builds fine on our API server, but not the client.

The client is being used when I call const defaultClient = SibAPI.ApiClient.instance This is identical to how it is done on the server.

When building on the client I get


Module not found: Can't resolve 'ApiClient'
null
Error from chokidar (D:\): Error: EBUSY: resource busy or locked, lstat 'D:\DumpStack.log.tmp'
shubhamUpadhyayInBlue commented 3 years ago

Hey I will work on it and try to reproduce it at our end.

ShyamKatti commented 3 years ago

Exact same issue, please look into it.

shubhamUpadhyayInBlue commented 3 years ago

Hey!

If you are still facing the issue after webpack config change please send me steps so that I can replicate it and help you better. By the time I will take a look again and share if I find anything useful. Thanks

RupertDunmil commented 3 years ago

Yeah, we are having the same issue as well, causing pretty big problems for our users. May need to go with another provider if this isn't fixable soon.

shubhamUpadhyayInBlue commented 3 years ago

Hi @RupertDunmil

Had we been able to replicate the issue on our side we would have already fixed it. But unfortunately, we haven't been able to.

Thanks!

shubhamUpadhyayInBlue commented 3 years ago

Thank you for reporting this issue. However, I would request you to please report this issue with our support team from you account (https://account.sendinblue.com/support --> please create a new ticket) as it might require further investigation and we will look into it. It will be better than sending it via email to me.

Please mention these details in the ticket:

shubhamUpadhyayInBlue commented 3 years ago

Hey

I tried to again replicate the same error on my local machine. But, no luck I could still run it. The configuration/versions I am testing on:

OS: macOS 11.2.1 NodeJS: 14.15.4 NPM: 7.15.1 sib-api-v3-sdk: 8.2.0

Please check out the attached screenshot from my laptop. Could you please confirm if it is coming from a specific route or in all of them?

Screenshot 2021-06-02 at 9 03 09 AM

Thanks!

worldtok commented 3 years ago

Having issue relating to this

Module not found: Error: Can't resolve 'model/UploadImageToGallery' in 'C:\xampp\htdocs\project\node_modules\sib-api-v3-sdk\src'
Did you mean './model/UploadImageToGallery'?
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).
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.
shubhamUpadhyayInBlue commented 3 years ago

Hi @worldtok I will check this today.

yaron1m commented 2 years ago

Hi @worldtok I will check this today.

Any update?

shubhamUpadhyayInBlue commented 2 years ago

HI @yaron1m Unfortunately, I haven't been able to replicate this issue at our end. Can you help us with steps on how to replicate it or how you are trying to use it? Also, FYI we are using the latest version of this wrapper inside SIB internal projects and it is working fine. Thanks!

yaron1m commented 2 years ago

I invested some time in trying to make this work and gave up. I am now just using fetch with a POST request

sudheersuri commented 2 years ago

same issue, am running node 16.14.2 and npm 8.5.5 on windows

rafazafar commented 2 years ago

Same issue on MacOS (M1) 12.4 , Node 16.14.2 Gave up and used something else instead.

marcus-franzen commented 1 year ago

I could solve this issue by adding this to the webpack config:

module: { rules: [ ... { test: /\.js$/, parser: { amd: false, }, }, ], },

laubonghaudoi commented 1 year ago

Same issue here. Is there an official fix?

luisdanielbarros commented 1 year ago

Same issue, how do I this this?

qpre commented 1 year ago

The official fix seems to be "please patch your whole build process to spit CJS modules" (which you might not want to do your codebase is somewhat modern).

Using the fetch API with the right headers instead is definitely more effective (see link).

Based on style, I'm pretty sure the authors of the library thought "java" in javascript stood for Java the language.

Want a PR on how to expose a lib for multiple modules systems ?

oliverkidd commented 1 year ago

Having problems on this too. Any guidance?

EricHasegawa commented 1 year ago

closing because its been a couple years lol

laubonghaudoi commented 1 year ago

This is a perfect example of how you lose customers.

shubhamUpadhyayInBlue commented 1 year ago

Hi @laubonghaudoi Sorry to hear we could not help you with this. The reason is that we were not able to reproduce this issue in any way we tried.

We do have our new SDKs mainly with the replacement of api.sendinblue.com domain with api.brevo.com domain. If you want you can try them out as here:

hassan34319 commented 1 year ago

Any fix till now? Started facing the error as soon as I upgraded to next js 13.4. Worked fine before that

gugiserman commented 1 year ago

Same issue on a modern nextjs environment server-side.

I will have to consider shifting to a different service entirely since our workflow is supposed to heavily rely on the API integration 😢 It's unfortunate because it was definitely our favourite option so far.

hassan34319 commented 1 year ago

Seems like this issue persists for those using nextjs 13.4

On Thu, 13 Jul 2023, 06:09 Gustavo Giserman, @.***> wrote:

Same issue on a modern nextjs environment server-side.

I will have to consider shifting to a different service entirely since our workflow is supposed to heavily rely on the API integration 😢 It's unfortunate because it was definitely our favourite option so far.

— Reply to this email directly, view it on GitHub https://github.com/sendinblue/APIv3-nodejs-library/issues/101#issuecomment-1633392800, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5DSV4ZBBX7WP72MMUAHYX3XP5DFVANCNFSM43RPIBWQ . You are receiving this because you commented.Message ID: @.***>

gugiserman commented 1 year ago

Having success replacing sdk with fetch and hitting the endpoints directly. Not a huge problem but I wish I didn't have to rewrite all sdk methods 😆

Maybe the documentation should also point out the api-key header must go in the Api-Key custom header. Unless its discouraged to implement it this way?

hassan34319 commented 1 year ago

Can you please send the code. I am really stuck and cant figure a way out.

On Thu, 13 Jul 2023, 06:32 Gustavo Giserman, @.***> wrote:

Having success replacing sdk with fetch and hitting the endpoints directly. Not a huge problem but I wish I didn't have to rewrite all sdk methods 😆

Maybe the documentation should also point out the api-key header must go in the Api-Key custom header. Unless its discouraged to implement it this way?

— Reply to this email directly, view it on GitHub https://github.com/sendinblue/APIv3-nodejs-library/issues/101#issuecomment-1633407247, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5DSV4YDC2GEIEEF3NAD6WTXP5F4JANCNFSM43RPIBWQ . You are receiving this because you commented.Message ID: @.***>

gugiserman commented 1 year ago

Can you please send the code. I am really stuck and cant figure a way out.

@hassan34319 here is an example of a contact creation request. hope it helps.

Based on https://developers.brevo.com/reference/createcontact

const request = await fetch('https://api.brevo.com/v3/contacts', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Api-Key': process.env.BREVO_API_KEY,
  },
  body: JSON.stringify({
    email: 'email@example.com',
    listIds: [2], // use your own list ids...
    attributes: {
      SOMETHING: 'something',
    },
  }),
})

if (request.ok) // success
else // failed
hassan34319 commented 1 year ago

Importing import * as SibApiV3Sdk from @.***/client' is also working.

On Thu, Jul 13, 2023 at 7:29 AM Gustavo Giserman @.***> wrote:

Can you please send the code. I am really stuck and cant figure a way out.

@hassan34319 https://github.com/hassan34319 here is an example of a contact creation request. hope it helps.

Based on https://developers.brevo.com/reference/createcontact

const request = await fetch('https://api.brevo.com/v3/contacts', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Api-Key': process.env.BREVO_API_KEY, }, body: JSON.stringify({ email, listIds: [2], // use your own list ids... attributes: { SOMETHING: 'something', }, }),}) if (request.ok) // successelse // failed

— Reply to this email directly, view it on GitHub https://github.com/sendinblue/APIv3-nodejs-library/issues/101#issuecomment-1633448153, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5DSV42BLS2MI54XEKCJTKLXP5MQ5ANCNFSM43RPIBWQ . You are receiving this because you were mentioned.Message ID: @.***>

hassan34319 commented 1 year ago

FIx with nextjs 13.4 is using this library instead : https://github.com/sendinblue/APIv3-typescript-library/tree/main

On Thu, Jul 13, 2023 at 8:07 AM Hassan Iqbal @.***> wrote:

Importing import * as SibApiV3Sdk from @.***/client' is also working.

On Thu, Jul 13, 2023 at 7:29 AM Gustavo Giserman @.***> wrote:

Can you please send the code. I am really stuck and cant figure a way out.

@hassan34319 https://github.com/hassan34319 here is an example of a contact creation request. hope it helps.

Based on https://developers.brevo.com/reference/createcontact

const request = await fetch('https://api.brevo.com/v3/contacts', { method: 'POST', headers: { 'Content-Type': 'application/json', 'Api-Key': process.env.BREVO_API_KEY, }, body: JSON.stringify({ email, listIds: [2], // use your own list ids... attributes: { SOMETHING: 'something', }, }),}) if (request.ok) // successelse // failed

— Reply to this email directly, view it on GitHub https://github.com/sendinblue/APIv3-nodejs-library/issues/101#issuecomment-1633448153, or unsubscribe https://github.com/notifications/unsubscribe-auth/A5DSV42BLS2MI54XEKCJTKLXP5MQ5ANCNFSM43RPIBWQ . You are receiving this because you were mentioned.Message ID: @.***>

zidkim commented 1 week ago

Same module resolution issue. Seems to not work with NextJS 14's native api routes. All you have to do is spin up a new NextJS project (14), and follow NextJS documentation while trying to load the library, whether its

import SibApiV3Sdk from "sib-api-v3-sdk"; or const SibApiV3Sdk = require("sib-api-v3-sdk");

It does work however if I'm in a less abstracted node environment. That being said, the former should work and is an expected standard.