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

Breaking build after upgrade to contentful 11 #2332

Open
edlerd opened this issue Sep 21, 2024 · 4 comments
Open

Breaking build after upgrade to contentful 11 #2332

edlerd opened this issue Sep 21, 2024 · 4 comments

Comments

@edlerd
Copy link

edlerd commented Sep 21, 2024

Building a nextjs application after upgrade of contentful from 10.15.1 to 11.0.2 fails due to the below message

Creating an optimized production build ...
Failed to compile.

./node_modules/contentful/dist/contentful.cjs
Module not found: Can't resolve 'fs'

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
./pages/index.tsx


> Build failed because of webpack errors

After downgrade to 10.15.1 the build is passing. I would like to upgrade, but how to make the build pass? Are you missing to declare the dependency to fs?

Happy to provide more info if needed.

@axe312ger
Copy link
Collaborator

We can not declare fs as a dependency, as it is a nodejs module.

You have two options:

  1. tell nextjs to use the Contentful SDK only on server side
  2. tell your nextjs inject replacement dependencies for nodejs modules.

This stack overflow answer should give you all the details and code snippets you need: https://stackoverflow.com/a/68098547

@axe312ger
Copy link
Collaborator

Rollup users might want to use this plugin: nodeResolve({ browser: true, preferBuiltins: false })

@edlerd
Copy link
Author

edlerd commented Sep 28, 2024

Thanks for the suggestions, they didn't resolve the issue for me. But I found a workaround with the info you provided:

Moving all data loading into getServerSideProps lets the build pass with contentful 11. Previously I was doing that in getInitialProps, which seems to be unsupported since the update.

@axe312ger
Copy link
Collaborator

@edlerd depends, getServerSideProps executes on the server, while the other will execute on the browser clients as well. You might have/had issues with your client side bundling.

Glad it works for you now. I would recommend to load data server side as much as you can!

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