4

Getting Error TypeError: Cannot read properties of undefined (reading 'value') while Setting Up Sitecore Headless in Sitecore 10.3

Please find the attached screenshot for reference

enter image description here

I have diligently followed all the steps outlined in the blog https://www.getfishtank.com/blog/how-to-setup-xm-cloud-sitecore-10-sxa-headless-and-nextjs.

However, I am still encountering this error at the end of the setup process.

Could anyone offer insights or suggestions to resolve this issue?

3 Answers 3

2

You might not have the field "pageTitle" field defined in your page template. Please try and change the line to

fields?.pageTitle?.value?.toString()
2
  • I have previously attempted to include a similar conditional code. After modifying the line as per your suggestion, the page appears with 2 links. Additionally, when accessing the page through the Experience Editor, I am unable to access the toolbox, and placeholders are also not visible. Commented Feb 19 at 9:50
  • Can you check the console errors? Seems like both the issues are unrelated Commented Feb 19 at 21:34
1

Always check the fields in the layout service before accessing them in your frontend code.

You can either open the layout service through the URL /sitecore/api/layout/render/jss?item=[path]&sc_lang=[language]&sc_apikey=[key]

or use the browser console window.__JSS_STATE__.

Don’t forget to implement null checks on your fields to prevent code breaks.

1

To resolve the error encountered during the setup of Sitecore Headless SXA and Next.js for Sitecore 10.3, ensure all configuration files, including .env and config.js, are correctly set with appropriate values such as JSS_EDITING_SECRET and API Key.

Double-check the JSS API Key creation and verify the GraphQL endpoint URL and rendering host settings.

Confirm that all necessary Node modules are installed and the site definition in Sitename.config matches your Sitecore items.

Restart IIS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.