简体   繁体   English

不确定如何调试 `uid: prismicDocument.uid ?? 无效 0` 与 Prismic 和 Next.js 站点

[英]Not sure how to debug `uid: prismicDocument.uid ?? void 0` with Prismic and Next.js site

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:我有一个使用Prismic CMS 的 Next.js 项目,该站点在本地运行良好,但最近有人更改了文档中的一些副本,这导致在生产版本中出现以下回溯:

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:在我使用@prismicio/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:后来,我通过从我创建的 UID 中提取内容来使用客户端:

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?这在本地运行良好,所有副本更改都反映在本地呈现的 output 中。除了删除和/或重新创建文档并尽可能添加日志外,是否有调试此(有点神秘)Prismic 错误的最佳实践?

That version of @prismicio/client contains code using nullish coalescing (the ?? operator).该版本的@prismicio/client包含使用无效合并( ??运算符)的代码。

It's possible you are using a version of Node.js in production (ie Netlify) that does not support ??您可能在生产环境(即 Netlify)中使用不支持 Node.js 的版本?? . . It is supported as of Node.js 14.从 Node.js 14 开始支持。

Updating your Netlify build environment to use at least Node.js 14 should fix the issue.更新您的 Netlify 构建环境以使用至少 Node.js 14 应该可以解决这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM