apostrophe-cms - ApostropheCMS - 错误:不能从嵌套在另一个对 render() 调用中的 Nunjucks 辅助函数调用 render()
问题描述
我在生产中运行了撇号 CMS 项目。最近我更新了应用程序并更新了 Apostrophe CMS 版本。在此之后,我反复收到此错误:
Error: render() must not be called from a Nunjucks helper function nested inside another call to render(). Use partial() instead.
问题是我无法检查此错误的来源。这也是非常随机发生的。在开发服务器中,我没有这个问题并且无法复制以找到根本原因。在上述错误之后,它还显示了应该发生错误的 Nunjucks 错误行,但该错误行是无用的,因为如果我检查模板,则指定的错误行中没有任何内容。
我检查了撇号 CMS 源代码。它在这里抛出错误:
...
// Implements `render` and `renderString`. See their
// documentation.
self.renderBody = function(req, type, s, data, module) {
if (self.contextReq && (req !== self.contextReq)) {
throw new Error('render() must not be called from a Nunjucks helper function nested inside another call to render(). Use partial() instead.');
}
...
在我的应用程序代码中,我没有在render()
任何地方使用过该功能。请注意,我在任何类型的页面中都会随机收到此错误。我创建了几个页面,其中也出现了错误。即使在notFound.html
模板中(我没有任何小部件,它只是扩展了layout.html
)我也得到了错误。
更新
根据 Nunjucks 错误行,我发现错误发生在我的my-pieces-pages/views/show.html
模板上,位于以下行:
{{ apos.singleton(piece, 'picture', 'apostrophe-images') }}
...
作品中picture
的字段具有以下外观:
{
name: "picture",
label: "Picture",
type: "singleton",
widgetType: "apostrophe-images",
options: {
limit: 1
}
},
...
解决方案
在 github 问题中也对此进行了讨论。最终确定所有遇到此问题的人都在使用 Node 12.x 的早期版本。
根据尝试过的每个人的说法,最新版本的 Node 12.x 无法重现该问题。
因此,升级到 Node 12.x 的最新次要和补丁级别版本就是这个问题的答案。但是,如果找到使用最新 Node 12.x 版本重现它的方法,则应通过 github 提交可靠重现它的步骤,并且可以重新打开票证。
为了完整起见,还应注意模板代码不应尝试执行异步函数或接受回调的函数。我了解您的情况没有发生这种情况。
推荐阅读
- uitableview - tvOS UITableView 黑色背景
- c# - 正则表达式模式忽略输入字符串中的内括号
- javascript - 为什么这些日期不能在 reactjs 中正确显示?
- php - 如何将变量名从控制器传递到 Symfony 中的树枝文件?
- android-recyclerview - Android RecyclerView notifyItemRangeChanged 正在替换旧数据
- r - 如何在 R 中标记散点图的点?
- javascript - 将公用文件夹中的 css 导入任何反应组件
- python - 如何让我的机器人更快地播放音频?(discord.py 重写)
- api - Garmin 连接 OAuth 用户访问令牌 签名方法 HMAC-SHA1 的签名无效
- c# - Unity - 发现多个文件具有独立于操作系统的路径 'META-INF/androidx.lifecycle_lifecycle-runtime.version' 有关详细信息,请参阅控制台