Uncertain about troubleshooting the `uid: prismicDocument.uid ?? void 0` error on a Prismic and Next.js website?

Currently, I am working on a Next.js project integrated with the Prismic CMS. The website runs smoothly in my local environment, however, after some recent updates to the content, I encountered the following error during production builds:

2:42:19 PM: /opt/build/repo/node_modules/@prismicio/helpers/dist/documentToLinkField.cjs:9
2:42:19 PM:     uid: prismicDocument.uid ?? void 0,
2:42:19 PM:                               ^
2:42:19 PM: SyntaxError: Unexpected token '?'
2:42:19 PM:     at wrapSafe (internal/modules/cjs/loader.js:1054:16)
2:42:19 PM:     at Module._compile (internal/modules/cjs/loader.js:1102:27)
2:42:19 PM:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
2:42:19 PM:     at Module.load (internal/modules/cjs/loader.js:986:32)
2:42:19 PM:     at Function.Module._load (internal/modules/cjs/loader.js:879:14)
2:42:19 PM:     at Module.require (internal/modules/cjs/loader.js:1026:19)
2:42:19 PM:     at require (internal/modules/cjs/helpers.js:72:18)
2:42:19 PM:     at Module.<anonymous> (/opt/build/repo/node_modules/@prismicio/helpers/dist/asLink.cjs:4:29)
2:42:19 PM:     at Module._compile (internal/modules/cjs/loader.js:1138:30)
2:42:19 PM:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10) {
2:42:19 PM:   type: 'SyntaxError'

In the code using @prismicio/client, I have defined a Client object as follows:

import * as prismic from "@prismicio/client";

const repositoryName = process.env.NEXT_PUBLIC_PRISMIC_REPO_NAME;
const endpoint = prismic.getRepositoryEndpoint(repositoryName);

export const createClient = () => {
    return prismic.createClient(endpoint, {
        accessToken: process.env.PRISMIC_ACCESS_TOKEN,
    });
};

Later on, I retrieve content using the UID that was created:

let contentBlob = await client.getByUID("customUID", params.partner);

While this setup works perfectly locally, the error persists in the production build. Aside from attempting document deletion and recreation and adding logs for debugging purposes, I am seeking better practices to troubleshoot this perplexing Prismic issue.

Answer №1

The current edition of @prismicio/client has incorporated code utilizing the nullish coalescing (the ?? operator).

There is a possibility that you might be operating on a version of Node.js in your production environment (e.g., Netlify) that does not support the ?? operator. It should be noted that it is officially supported starting from Node.js 14.

To resolve this issue, consider updating your Netlify build environment to utilize at least Node.js 14.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Custom AngularJS directive for ensuring the selection of a required HTML element

Today brings another question as I continue working on my web application. I've encountered an issue with the 'required' attribute not being widely supported in major browsers. The attribute only works if the first option value is empty, whi ...

When the radio button is selected, show a variety of buttons

I'm facing an issue with rendering different buttons for two radio buttons within a view. Here is the rendered HTML code for the radio buttons: <input checked="checked" id="Isattending_0" name="Isattending" type="radio" value="Yes" /> <inpu ...

Ways to rearrange items in the navigation bar?

I am working with a Bootstrap template and I am trying to adjust the layout to be right-to-left (RTL). Currently, when I set the site title to RTL in the navbar, the buttons in the navbar also switch to RTL alignment. This is not the desired layout I want. ...

Angular 6 - Outdated Functions

I'm having trouble updating the request options as they are now deprecated. I can't seem to locate the alternative option for this. Can anyone offer some assistance? import { Injectable } from '@angular/core'; import { HttpClient } fr ...

Is there a way to access local storage data within the getServerSideProps function?

I am currently working with NextJS 12 and facing an issue while trying to access the local storage object. Whenever I attempt to use localStorage within getServerSideProps, I encounter the error message ReferenceError: localStorage is not defined. I'v ...

Alert box in Vue.js

Embarking on my journey with VueJS. I previously implemented an alert box using jQuery. Now, I am attempting to recreate that in VueJS. Here is my current progress: 1- Developed a component named NovinAlert.vue which includes: <template> & ...

Include personalized headers to the 'request'

I have configured my express server to proxy my API using the following setup: // Proxy api calls app.use('/api', function (req, res) { let url = config.API_HOST + req.url req.pipe(request(url)).pipe(res) }) In this instance, confi ...

No data found in Node.js after receiving AngularJS POST request

I've been working on sending a straightforward POST request to my server using AngularJS. The request successfully goes through and reaches the controller on the backend, but strangely, req.data is appearing as undefined. Front End Controller: funct ...

You should be providing a string value as expected. It seems that you may have overlooked exporting your component from the correct file it was defined in, or perhaps there is confusion with default and named

I encountered a strange error despite meticulously organizing and exporting/importing files. The code is structured from components to the App render method. Item.js import React from 'react'; import './Global.css' const Item = ({data ...

Is there a way to send the image's name as a parameter?

I am facing a challenge in achieving a specific task and need some guidance. My current approach involves passing the image name as a parameter to the cancelimage.php script, but it seems like I am not utilizing the variable 'image_file_name' cor ...

What is the best way to create a sliding <nav> effect when a <div> is clicked?

Hello! I am looking for a solution that will cause the navigation contents to slide out from the left when the div class "bt-menu" is clicked. It should also slide back in to the left either when the div is clicked again or when anywhere outside of the nav ...

Create your masterpiece on a rotated canvas

My goal is to draw on a canvas using the mouse, even after rotating and scaling the canvas container. The issue I am facing is that the mouse coordinates get affected by the rotation and scaling, making it difficult to draw correctly. I have tried switch ...

Issue with defining Zoom SDK in Next.js and React as self is not defined

Experimenting with Next.js and attempting to integrate the Zoom SDK Error: ReferenceError: self is not defined Encountering a ReferenceError: self is not defined while trying to incorporate the Zoom SDK into Next.js. Here is a snippet of my code that&apo ...

This JavaScript operates in solitude, unable to collaborate with other JavaScripts

I received this code from an outsourced programmer: <script type="text/javascript"> $(function(){ $('#notif-icons > li > a, #top-menu > li > a').click(function() { var clicked = $(this).next('.popup-notif&a ...

Getting access to props within a child component's mounting phase

It is commonly understood that when the child component is mounted before the parent component, trying to access props in the child component's mounted period will result in null. However, I recently came across a scenario where props were successful ...

Is it possible for an object hidden in the DOM using jQuery to magically reappear when you click the back button or use the bfc

Is there a way to prevent a box from reappearing when using the back button on a webpage? On my website, there is a box that shows up on the first visit. However, when navigating using the back buttons on the site or the browser back button, the box appea ...

What is the best way to utilize MongoDB aggregate in this particular scenario?

How can I optimize this mongoose query to improve performance and reduce size for production? const currentYear = (new Date).getFullYear() const usedCars = await CarModel.find({ ModelYear: {$lte: currentYear - 1} }).limit(10) const recentCars = await Car ...

Hide bootstrap card on smaller screens such as sm and md

Utilizing the Bootstrap 4.1 card component, I showcase categories within the right sidebar - check out a sample image of the card here: Card example image; When viewing on smaller screens, it's preferable to collapse this large card as shown in this ...

Binding multiple forms in backend ASP.NET MVC using Managed Extensibility Framework (MEF)

We are facing a challenge where we need to send multiple forms in one Ajax (jQuery) Call to an ASP application. The jQuery code we are using is as follows: var formContainer = { Form1 : form1.serialize(), Form2 : form2.serialize() } ...

"Ionic with Angular is facing an issue where ion-radio element cannot be set as checked by default

Having trouble selecting a radio button in a radio list. Can anyone help? Any assistance would be greatly appreciated. This is how I've been attempting it: <div class="list"> <ion-radio ng-repeat="item in goalTypeList" ...