Generate: [error] Cannot read property 'data' of undefined

Hello,

I have a problem with the apiOptions.routes in the Prismic module.

In our project we have childeren under expertises which has a child that has a different layout called data-en-customer-intelligence (DCI). The first part of the DCI page has data which gets picked up by /services/expertises/:uid and ends up generating an error in the build and outputting a page without content.

Running "@nuxtjs/prismic": "^1.2.4",

nuxt.config.js

prismic: {
	...
	apiOptions: {
		routes: [
			...
			{
				type: 'expertise',
				path: '/services/expertises/:uid',
			},
			{
				type: 'expertise_dci',
				path: '/services/expertises/data-en-customer-intelligence/:uid',
			},
		],
	},
},

Hi Max,

I'm not quite sure how the page giving the error Cannot read property 'data' of undefined could be related to the route resolver in this case. Can you explain further or better yet share the code for the page which is not building correctly?

Thanks.

This issue has been closed due to inactivity. Flag to reopen.

re-opened for @maxvdschee

He, I have updated the repo on github, there are now two instances where it happens:

{
	type: 'at_work',
	path: '/actueel/at-work/:uid',
},
{
	type: 'expertise_dci',
	path: '/services/expertises/data-en-customer-intelligence/:uid',
}

It seems to not like the - part but only if it's a repeatable type

for the single type page over-ons it has no problem with the - in the url.

hope this helps.

Cheers!

Does the page structure of the 'pages' directory reflect the path that you have defined here?

Yes, it's defined the same way

Can you share with me your project code so I can help debug this?

Hey Max,

I deployed your project on Netlify and had no issues with the route:

He Phil,

I see that page is indeed working, it still produces an error in the build step which is fine for now.

CI build log:

...
[error] Cannot read property 'data' of undefined
  at asyncData (pages/services/expertises/_uid.js:3865:24)
  at runMicrotasks (<anonymous>)
  at processTicksAndRejections (internal/process/task_queues.js:97:5)
...
[error] Error generating route "/services/expertises/data": Page not found
...
[success] Generated route "/services/expertises/data-en-customer-intelligence/online-marketing"
[success] Generated route "/services/expertises/data-en-customer-intelligence/data-intelligence"
[success] Generated route "/services/expertises/data-en-customer-intelligence/customer-intelligence"

So if we take a look at the actueel page the second item in the list should have an url like: .../actueel/at-work/at-work-max/

but the url is .../actueel/at

Local build log:

...
Error generating route "/actueel/at": This page could not be found   

This is something that I can not fix and doesn't build a page that is still workable.

OK, Thanks for pointing this out, I see these errors now.

You'll be happy to learn I spent more than an hour trying to figure out why /actueel/at-work/at-work-max/ wasn't working instead of /actueel/at-work/max-at-work/ :man_facepalming: :joy:

I then spent more time looking in to this and I don't think the issue is coming from the route resolver, as the route resolver doesn't really have anything to do here since there are no dynamic page folders in the /actueel/at-work/max-at-work/ route. For a route like this, since there are no dynamic folders, it's enough to use the link resolver.

The actual generation of that route is handled by Nuxt, which it seems is failing on that folder name because of the hyphen '-' like you suggested. If you remove this from the route resolver the same error occurs. I also noticed you were still you using the plugins 'Static' and 'Crawler' these are unnecessary as this is done by Nuxt now as I mentioned above. I removed these plugins, but no joy on the issue.

So to me, it seems like the issue is coming from either the nuxt or @prismic/nuxt plugins. I'm going to bring this up with the team and see what I can figure out about the issue.

Issue: Folders with hyphens '-', causing the route generation to fail. · Issue #136 · nuxt-community/prismic-module · GitHub

@maxvdschee My bad it does indeed seem to work with the just link resolver https://nostalgic-noether-e1c898.netlify.app/actueel/at-work/max-at-work

One of the team thinks it's like you suggested an issue with how the apiOptions.routes option is processing that folder. The workaround now is just to use the linkresolver for this route and it should be fine. @lihbr Has created a ticket in the tracker about this.

OK, maybe this doesn't work as I thought :joy: Still investigating.

Sorry my bad, should have checked better before posting, sorry for wasting your time :slight_smile:

Yeah I tried a full upgrade and tried to remove those plugins but Indeed doesn't produce any better results.

I check the page, it does work with the hydrated version of the page but the static HTML is page not found content.

OK, so it should work using just the linkresolver, in fact since none of your routes have dynamic folder names the link resolver is all you need right now.

Can you explain a little further what you mean by this?

Okay I will try that.

On the page https://nostalgic-noether-e1c898.netlify.app/actueel/at-work/max-at-work it showed before It couldn't find the page but that has been resolved now.

If you look at the source version view-source:https://nostalgic-noether-e1c898.netlify.app/actueel/at-work/max-at-work none of the meta and content is showing up in the generated version and just has the default loader of nuxt in body. this should be generated content from that page.

I see that. It must be to do with how it's deployed, because locally everything is built correctly.

Have you tried going full static?

I have tried but the older crawler and static plugin didn't work with that, I will change it to the newest implementation and try out the full static version.

1 Like