-
Notifications
You must be signed in to change notification settings - Fork 2
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
TypeError: Amadeus is not a constructor #4
Comments
Hi @SKTimTam, thanks for reaching out regarding this error! It seems that this issue is not directly related to the library, my guess is because you are using the command I can redirect you to a reference project I made to demonstrate how to use this library with Next.js 15. Let me know if you keep having errors when you start your project. |
I'm having this same problem! It's obvious that you did something incorrect in your library, because the simple solution in your readme doesn't work for express and node applications. I'm however, struggling to figure out why. |
This is incredibly sad, I'm going to have to go to sleep without solving the issue with the broken library :-( |
Can you provide me with the code that is causing the error? Because I just tested with a simple express app and everything seems to be working fine. You can test this code on your machine and check if it causes the same problem, so I can know if it's an issue related to node.js version. import express, { Request, Response } from "express";
import Amadeus, { FlightOffersSearchGetParams } from "amadeus-ts";
import dotenv from "dotenv";
// App setup
const app = express();
app.use(express.json());
app.use(express.urlencoded({ extended: true }));
dotenv.config();
const amadeus = new Amadeus({
clientId: process.env.AMADEUS_CLIENT_ID,
clientSecret: process.env.AMADEUS_CLIENT_SECRET,
});
// Routes
app.post("/flights", async (req: Request, res: Response) => {
const {
adults,
originLocationCode,
destinationLocationCode,
departureDate,
}: FlightOffersSearchGetParams = req.body;
const response = await amadeus.shopping.flightOffersSearch.get({
originLocationCode,
destinationLocationCode,
departureDate,
adults,
});
return res.status(200).json({ data: response.data });
});
// Connection setup
const PORT = process.env.PORT || 3001;
app.listen(PORT, () => {
console.log(`Listening on port ${PORT}`);
}); |
Thanks for the quick reply! Unfortunately, I reset all my changes and went back to the JS npm package. I have a feeling it could be related to our tsconfig?
I did spend a lot of time trying to switch between We are on node 20.15 and
The error would happen not during compile time but runtime, as soon as the
is executed. I have placed it as a global property (error on I even copied index.d.ts and index.js into our project and removed the package and still had the issue. I imagine this is something quite simple, but I am a mobile developer so I'm not seeing it. Hopefully a config issue on our end but seems like a common configuration since I'm not the only one. If I have some time later I'll try to give a minimum reproducible example if the config above doesn't provide any leads. |
Thank you for the details you provided. But unfortunately I haven't been able to reproduce the error you encountered even when using your tsconfig and nodejs 20.15.0. Still everything worked as expected! It would be really helpful if you could provide a repo that has this issue so I can inspect it and hopefully manage to find the cause of this error. |
I'm affected also, in a express project. A workaround is using this import * as A from 'amadeus-ts';
import { AMADEUS_CLIENT_ID, AMADEUS_CLIENT_SECRET } from '@/constants';
const Amadeus = (A.default as any).default as typeof A.default;
export const amadeusClient = new Amadeus({
clientId: AMADEUS_CLIENT_ID,
clientSecret: AMADEUS_CLIENT_SECRET,
}); instead of import Amadeus from "amadeus-ts";
import { AMADEUS_CLIENT_ID, AMADEUS_CLIENT_SECRET } from '@/constants';
export const amadeus = new Amadeus({
clientId: AMADEUS_CLIENT_ID,
clientSecret: AMADEUS_CLIENT_SECRET,
}); |
Hi hope you are doing well.
Getting this error when trying to use the the Amadeus constructor. when i run node --import=tsx server.ts
below is my code
Do you have suggestions on what could be wrong?
The text was updated successfully, but these errors were encountered: