prismicH.asHTML() Pug Error - Can not read properties of undefined

Hello all,

I am using Prismic with Express and Pug. I've been trying to render a rich text field which is a part of a slice (called content). I would like to take advantage of the prismic helpers (prismicH.toHTML()) but I'm running into an error when I use prismicH in the .pug file.

Cannot read properties of undefined (reading 'asHTML')

The field is a rich text field. Screenshot of the slice below:

Here's the .pug code.

           each slice in
				if slice.slice_type == 'title'
				if slice.slice_type == 'content'

Here's the weird part. If I use prismicH.asHTML in express and console.log the result, I get the correct response.

Express.js /about Route:

  app.get('/about', async (req, res) => {
    const document = await client.getSingle('about') => {
      if (section.slice_type == 'content'){

Express Response from code above

As you can see, the strong and em tags are applied when I console.log the result in express, but attempting to use the same syntax in pug results in the error above. Sorry if this is a newby question, I'm fairly new to front end development.

Any help is appreciated. I can send my repo or any additional information if needed. Thank you!

Also of note, if I bypass the prismicH.asHTML function and put content_details on a simple p tag, it prints out the object.



				if slice.slice_type == 'content'
								//- .about__content__details=prismicH.asHTML(slice.primary.content_details)

Hello @mgcherneski

Welcome to the Prismic community, and thanks for reaching out to us.

How are you setting Middleware to set local variables (prismicH) in the app.js file? Could you please paste that file?


Hello @Priyanka, thanks for the quick reply!

Here's the middleware.

app.use((req, res, next) => {
  res.locals.ctx = {

I got it from here. Set up Prismic with Express - Documentation - Prismic


I got the html, with markup, to appear on the site by prefixing ctx before prismicH on my .pug file.

New Version:

				if slice.slice_type == 'content'

The markup on the webpage:

Quick final update, in order to get the HTML to render as HTML rather than with escaped tags, I needed the ! character. Final code looks like this:


Thanks for the help! I'm going to close the issue.

Great. I am happy to help. Feel free to reach out to us if you have any questions.

1 Like