In NextJs the contentful library is not loading when it's used in the API route.ts file in production.
In development it all working as expected, but when deployed by Vercel as a function the library is undefined.
import contentful from 'contentful';
Here contentful is undefined.
And Sentry is giving back the following error:
TypeError: Cannot read properties of undefined (reading 'getEntries')
Steps to Reproduce
Init next js app as App router.
Fetch contentful's getEntries from /app/api/contentful/route.ts
The library is not initialising correctly in node 20.x environment.
Environment
NextJs version: next@14.2.5
Contentful version: contentful@10.13.1
I'm using the REST api of Delivery.
Expected Behavior
getEntries
load the contentActual Behavior
In NextJs the contentful library is not loading when it's used in the API route.ts file in production. In development it all working as expected, but when deployed by Vercel as a function the library is undefined.
Here contentful is undefined.
And Sentry is giving back the following error:
Steps to Reproduce
Environment
NextJs version: next@14.2.5 Contentful version: contentful@10.13.1 I'm using the REST api of Delivery.