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.