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

suggestions function not working #568

Closed
abiodunt97 opened this issue Jul 15, 2022 · 11 comments
Closed

suggestions function not working #568

abiodunt97 opened this issue Jul 15, 2022 · 11 comments
Assignees

Comments

@abiodunt97
Copy link

Referencing the documentation provided here: https://duffel.com/docs/api/places/get-place-suggestions

I implemented a quick function to test the suggestions function.

Duffel Component

var { Duffel } = require('@duffel/api');

const duffel = new Duffel({
  token: "duffel_test_XXX",
  debug: { verbose: true }
});

module.exports = duffel;

Router Component

var express = require("express");
var router = express.Router();
var duffel = require('../duffel');

router.get("/", async (req, res, next) => {
    const autosuggestion = await duffel.suggestions.list(
        {
        "query": "heathr"
      }
      )
    res.send(autosuggestion);
});

module.exports = router;

Error Message

TypeError: Cannot read properties of undefined (reading 'list')

It seems as though the suggestions function does not exist.

Please help.

@lapa182
Copy link
Contributor

lapa182 commented Jul 15, 2022

Hi @abiodunt97, thanks for reporting the issue! I see we documented how to integrate place suggestions endpoint, but unfortunately, we still didn't do the implementation on the SDK! I have raised the above to our team and will get back to you once it's implemented.

@lapa182
Copy link
Contributor

lapa182 commented Jul 15, 2022

@abiodunt97 we just add the method on our latest version! Let me know if we can help further!

@abiodunt97
Copy link
Author

abiodunt97 commented Jul 15, 2022

Thanks @lapa182, i've tried to implement it but i'm running into more issues.

Here is the error I get:

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\xxx\Desktop\xxx\app\xxx\server\node_modules\node-fetch\src\index.js from C:\Users\xxx\Desktop\xxx\app\xxx\server\node_modules\@duffel\api\dist\index.js not supported.
Instead change the require of C:\Users\xxx\Desktop\xxx\app\xxx\server\node_modules\node-fetch\src\index.js in C:\Users\xxx\Desktop\xxx\app\xxx\server\node_modules\@duffel\api\dist\index.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (C:\Users\xxx\Desktop\xxx\app\xxx\server\node_modules\@duffel\api\dist\index.js:1:75)
    at Object.<anonymous> (C:\Users\xxx\Desktop\xxx\app\xxx\server\src\routes\index.js:3:23)
    at Object.<anonymous> (C:\Users\xxx\Desktop\xxx\app\xxx\server\src\app.js:7:19)
    at Object.<anonymous> (C:\Users\xxx\Desktop\xxx\app\xxx\server\bin\www:31:11) {
  code: 'ERR_REQUIRE_ESM'
}

@abiodunt97
Copy link
Author

@lapa182

I managed to resolve the above by going into the index.js and changing the require('node-fetch') to import('node-fetch'), not sure why this version throws aan ERR_REQUIRE_ESM error.

Also, in this new version 1.13.0. I am getting the below error:

TypeError: i.default is not a function
    at $.<anonymous> (C:\Users\xxx\Desktop\xxx\xxx\xxx\server\api\node_modules\@duffel\api\dist\index.js:1:7334) 
    at Generator.next (<anonymous>)
    at C:\Users\xxx\Desktop\xxx\xxx\xxx\server\api\node_modules\@duffel\api\dist\index.js:1:809
    at new Promise (<anonymous>)
    at h (C:\Users\xxx\Desktop\xxx\xxx\xxx\server\api\node_modules\@duffel\api\dist\index.js:1:554)
    at $.request (C:\Users\xxx\Desktop\xxx\xxx\xxx\server\api\node_modules\@duffel\api\dist\index.js:1:6452)     
    at T.<anonymous> (C:\Users\xxx\Desktop\xxx\xxx\xxx\server\api\node_modules\@duffel\api\dist\index.js:1:1775) 
    at Generator.next (<anonymous>)
    at C:\Users\xxx\Desktop\xxx\xxx\xxx\server\api\node_modules\@duffel\api\dist\index.js:1:809
    at new Promise (<anonymous>)

Please help.

@abiodunt97
Copy link
Author

@lapa182 Any news on this would be much appreciated, thanks.

@lapa182
Copy link
Contributor

lapa182 commented Aug 2, 2022

Hi @abiodunt97, sorry I was off and wasn't able to help you before! Let me investigate the issue and will come back to you.

Regarding node-fetch, I have a feeling that's the version we use which is the newest node-fetch version which is built to be used as ESM.

Instead of manually updating to import('node-fetch') you can resolve the module and install the previous v2 version https://github.com/node-fetch/node-fetch#installation. Alternatively, you can compile the module on the framework settings you are using - Next.js for example allows you to transpile modules manually.

@lapa182
Copy link
Contributor

lapa182 commented Aug 3, 2022

Hey @abiodunt97, I just investigate the issue and I think it's the issue it's caused by the change you made to node-fetch.

Could you please add to your package.json the following line:

If you are using npm:

"overrides": {
    "node-fetch": "2.6.7"
  },

If you are using yarn:

"resolutions": {
    "node-fetch": "2.6.7"
  },

And them re-install your packages.

@abiodunt97
Copy link
Author

No luck, still getting the same error with the overrides option added,

@lapa182
Copy link
Contributor

lapa182 commented Aug 5, 2022

No luck, still getting the same error with the overrides option added,

Do you mean the ESM error or .default one? Also, could you say what node version are you using?

@lapa182
Copy link
Contributor

lapa182 commented Aug 10, 2022

@abiodunt97 we deployed a new version of the library, could you please check if the issue still persists? Could you try deleting your node_modules and reinstalling the packages?

@abiodunt97
Copy link
Author

A huge thank you @lapa182. It now works for me perfectly. Thanks for all your help.

@lapa182 lapa182 closed this as completed Aug 11, 2022
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