0

I have a Next.js project that uses the Prismic CMS, and the site works locally just fine, but recently someone changed some copy in a document and that's resulting in the following Traceback in the 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 my code itself using @prismicio/client, I am creating a Client object:

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,
    });
};

and later, I am using the client by pulling in content from a UID I created:

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

This works well locally, and all of the copy changes are reflected in the local rendered output. Besides deleting and/or recreating documents and adding in logs where I can, are there best practices for debugging this (somewhat mysterious) Prismic error?

Cassidy
  • 3,328
  • 5
  • 39
  • 76
  • 2
    Looks like the environment in which you are running this code does not yet support the `??` operator. Consider upgrading the nodejs version – Bergi Jan 30 '23 at 21:31

1 Answers1

1

That version of @prismicio/client contains code using nullish coalescing (the ?? operator).

It’s possible you are using a version of Node.js in production (i.e. Netlify) that does not support ??. It is supported as of Node.js 14.

Updating your Netlify build environment to use at least Node.js 14 should fix the issue.

Angelo Ashmore
  • 366
  • 1
  • 4