Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

250
Views
TypeError: Cannot set properties of undefined (Prismic DOM)

I'm encountering this error "TypeError: Cannot set properties of undefined (setting 'PrismicDOM')" in my local website.

I'm trying to integrate Prismic in my project where i'm using prismic-dom but it doesn't seem to work. This is the code in my app.js can you tell me how to resolve this problem?

require('dotenv').config()

console.log(process.env.PRISMIC_ENDPOINT, process.env.PRISMIC_CLIENT_ID)

const express = require('express')
const app = express()
const path = require('path')
const port = 3000

const Prismic = require('@prismicio/client')
const PrismicDOM = require('prismic-dom')

const initApi = req => {
  return Prismic.getApi(process.env.PRISMIC_ENDPOINT, {
    accessToken: process.env.PRISMIC_ACCESS_TOKEN,
    req
  })
}

const handlelinkResolver = doc => {
  // Define the url depending on the document type
  // if (doc.type === 'page'){
  //  return '/page/' + doc.uid;
  // } else if (doc.type === 'blog_post'){
  //  return '/blog/' + doc.uid;
  //  }
  // Default to homepage
  return '/'
}

app.use((req, res, next) => {
  res.locals.ctx = {
    endpoint: process.env.PRISMIC_ENDPOINT,
    linkResolver: handlelinkResolver
  }
  // add PrismicDOM in locals to access them in templates.
  req.locals.PrismicDOM = PrismicDOM
  next()
})

app.set('views', path.join(__dirname, 'views'))
app.set('view engine', 'pug')

app.get('/', (req, res) => {
  res.render('pages/home')
})

app.get('/personaggi', (req, res) => {
  res.render('pages/personaggi')
})

app.get('/detail/:uid', (req, res) => {
  res.render('pages/detail')
})

app.get('/gioco', (req, res) => {
  initApi(req).then(api => {
    api.query(
      Prismic.Predicates.at('document.type', 'gioco')
    ).then(response => {
      console.log(response)
      // response is the response object. Render your views here.
      res.render('pages/gioco')
    })
  })
})

app.listen(port, () => {
  console.log(`Example app listening on port ${port}`)
})
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!