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

Contentful lib return undefined deploying a NextJs app with Vercel in Node.js Runtime function environment #2302

Open
OttlikG opened this issue Aug 9, 2024 · 2 comments

Comments

@OttlikG
Copy link

OttlikG commented Aug 9, 2024

Expected Behavior

getEntries load the content

Actual 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.

import contentful from 'contentful';

Here contentful is undefined.

nextjs_blur

And Sentry is giving back the following error:

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

Steps to Reproduce

  1. Init next js app as App router.
  2. Fetch contentful's getEntries from /app/api/contentful/route.ts
  3. The library is not initialising correctly in node 20.x environment.

Environment

NextJs version: [email protected]
Contentful version: [email protected]
I'm using the REST api of Delivery.

@cotrimelias
Copy link

cotrimelias commented Aug 16, 2024

This doesn't seem to be Vercel specific, getting the same error on local.
To solve, change to:
import * as contentful from 'contentful';

@OttlikG
Copy link
Author

OttlikG commented Aug 20, 2024

Yeah that seems to be solved it. Thanks

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