Express Code:
app.get('/', async (req, res) => {
const devices = await gsmarena.catalog.getBrand("apple-phones-48");
const name = devices.map((device) => device.name);
res.json(name);
})
Nextjs Code:
import {gsmarena} from "gsmarena-api"
export async function GET() {
const devices = await gsmarena.catalog.getBrand("apple-phones-48");
const name = devices.map((device: any) => device.name);
return Response.json({ data: any })
}
When attempting to use the same code in Next.js, an error is encountered:
⨯ TypeError: Cannot read properties of undefined (reading 'catalog')
at GET (webpack-internal:///(rsc)/./src/app/api/phonelist/route.ts:9:78)
at D:\WEB D\specsync\node_modules\next\dist\compiled\next-server\app-route.runtime.dev.js:6:63815
at D:\WEB D\specsync\node_modules\next\dist\server\lib\trace\tracer.js:133:36
...
The same error persists when attempting to implement the code in React.
I am utilizing the Gsm arena API available at: https://github.com/nordmarin/gsmarena-api