在 @wordpress/scripts@28 的情况下,通过 create-block 命令创建的 Gutenberg 块,在 WordPress 6.5.4 中不被显示。

Gutenberg blocks created by the create-block command in the case of @wordpress/scripts@28 are not displayed in WordPress 6.5.4.

该问题已有答案,记个笔记,汇总一下。

https://github.com/WordPress/gutenberg/issues/62202

Wordpress block not showing after `npx @wordpress/create-block@latest` and activation

https://wordpress.org/support/topic/plugin-created-with-create-block-not-showing-inside-editor/

使用 create-block 命令创建的古滕堡区块,如果其使用 @wordpress/scripts 的版本是 28,则不能展示在编辑器中,这是一个严重的BUG。

究其原因,Gutenberg 是基于 React 开发的,@wordpress/scripts@28 构建的代码适用于新的 React 版本,而 WordPress 6.5.4 作为稳定版本还使用旧的 React 运行时。

来源:https://github.com/WordPress/gutenberg/issues/62202#issuecomment-2143692074

解决办法是在 create-block 命令创建完区块后,对区块项目依赖的 @wordpress/scripts 手动降级。

npm uninstall @wordpress/scripts
npm install @wordpress/scripts@27.9.0

降级后区块就出现了,但是是否有其他不利影响尚未可知。

此外,如果不对 @wordpress/scripts 降级,也可以通过将 WordPress 升级到 6.6 beta 来解决这个问题,但是使用非稳定版本用于生产环境是不明智的。

WordPress 项目过度的工程化,导致开发者除非对其开发进度持续关注,否则往往使人在遇到问题时手足无措。

posted @ 2024-06-10 00:11  钰琪  阅读(5)  评论(0编辑  收藏  举报