npx @wordpress/create-block 抛出错误 "Command failed with exit code 1: npm install @wordpress/scripts --save-dev" Gutenberg 自定义块插件

npx @wordpress/create-block throws an error "Command failed with exit code 1: npm install @wordpress/scripts --save-dev" Gutenberg custom block plugin

我正在开始学习如何为 WordPress Gutenberg 编写自己的自定义块模式。我找到了一个教程,它引导我完成在 wp-content/plugins 中创建一个名为“my-first-block”的新插件的步骤。

我已经安装了 node,正在尝试 运行 命令 npx @wordpress/create-block my-first-block。当我 运行 这个命令时,我收到以下错误,我认为这是在抱怨 @wordpress/scripts。抛出的第一个错误是 Error: Command failed with exit code 1: npm install @wordpress/scripts --save-dev 然后它继续显示一系列其他错误,每行以 npm ERR! Could not resolve dependency:

开头

这是完整的错误日志;

Error: Command failed with exit code 1: npm install @wordpress/scripts --save-dev
npm WARN ERESOLVE overriding peer dependency
npm WARN Found: prettier@2.2.1-beta-1
npm WARN node_modules/prettier
npm WARN   prettier@"npm:wp-prettier@2.2.1-beta-1" from @wordpress/scripts@19.2.1
npm WARN   node_modules/@wordpress/scripts
npm WARN     dev @wordpress/scripts@"*" from the root project
npm WARN   1 more (@wordpress/eslint-plugin)
npm WARN
npm WARN Could not resolve dependency:
npm WARN peer prettier@">=1.13.0" from eslint-plugin-prettier@3.4.1
npm WARN node_modules/eslint-plugin-prettier
npm WARN   eslint-plugin-prettier@"^3.3.0" from @wordpress/eslint-plugin@9.3.0
npm WARN   node_modules/@wordpress/eslint-plugin
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! Found: acorn@7.4.1
npm ERR! node_modules/acorn
npm ERR!   acorn@"^7.4.0" from espree@7.3.1
npm ERR!   node_modules/espree
npm ERR!     espree@"^7.3.1" from eslint@7.32.0
npm ERR!     node_modules/eslint
npm ERR!       eslint@"^7.17.0" from @wordpress/scripts@19.2.1
npm ERR!       node_modules/@wordpress/scripts
npm ERR!         dev @wordpress/scripts@"*" from the root project
npm ERR!       15 more (@wordpress/eslint-plugin, eslint-plugin-markdown, ...)
npm ERR!     espree@"^7.3.0" from @eslint/eslintrc@0.4.3
npm ERR!     node_modules/@eslint/eslintrc
npm ERR!       @eslint/eslintrc@"^0.4.3" from eslint@7.32.0
npm ERR!       node_modules/eslint
npm ERR!         eslint@"^7.17.0" from @wordpress/scripts@19.2.1
npm ERR!         node_modules/@wordpress/scripts
npm ERR!         15 more (@wordpress/eslint-plugin, eslint-plugin-markdown, ...)
npm ERR!   peer acorn@"^6.0.0 || ^7.0.0 || ^8.0.0" from acorn-jsx@5.3.2
npm ERR!   node_modules/acorn-jsx
npm ERR!     acorn-jsx@"^5.3.1" from espree@7.3.1
npm ERR!     node_modules/espree
npm ERR!       espree@"^7.3.1" from eslint@7.32.0
npm ERR!       node_modules/eslint
npm ERR!         eslint@"^7.17.0" from @wordpress/scripts@19.2.1
npm ERR!         node_modules/@wordpress/scripts
npm ERR!         15 more (@wordpress/eslint-plugin, eslint-plugin-markdown, ...)
npm ERR!       1 more (@eslint/eslintrc)
npm ERR!   1 more (acorn-globals)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peerOptional acorn@"^8.5.0" from terser@5.10.0
npm ERR! node_modules/terser
npm ERR!   terser@"^5.7.2" from terser-webpack-plugin@5.2.5
npm ERR!   node_modules/terser-webpack-plugin
npm ERR!     terser-webpack-plugin@"^5.1.4" from @wordpress/scripts@19.2.1
npm ERR!     node_modules/@wordpress/scripts
npm ERR!       dev @wordpress/scripts@"*" from the root project
npm ERR!     1 more (webpack)
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\username\AppData\Local\npm-cache\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\username\AppData\Local\npm-cache\_logs\debug.log
    at makeError (C:\Users\username\AppData\Local\npm-cache\_npx90e296436e9575\node_modules\execa\lib\error.js:59:11)
    at handlePromise (C:\Users\username\AppData\Local\npm-cache\_npx90e296436e9575\node_modules\execa\index.js:114:26)
    at processTicksAndRejections (node:internal/process/task_queues:93:5)
    at async module.exports (C:\Users\username\AppData\Local\npm-cache\_npx90e296436e9575\node_modules\@wordpress\create-block\lib\init-wp-scripts.js:19:2)
    at async module.exports (C:\Users\username\AppData\Local\npm-cache\_npx90e296436e9575\node_modules\@wordpress\create-block\lib\scaffold.js:103:3)
    at async Command.<anonymous> (C:\Users\username\AppData\Local\npm-cache\_npx90e296436e9575\node_modules\@wordpress\create-block\lib\index.js:91:6) {
  shortMessage: 'Command failed with exit code 1: npm install @wordpress/scripts --save-dev',
  command: 'npm install @wordpress/scripts --save-dev',
  exitCode: 1,
  signal: undefined,
  signalDescription: undefined,
  stdout: '',
  stderr: 'npm WARN ERESOLVE overriding peer dependency\n' +
    'npm WARN Found: prettier@2.2.1-beta-1\n' +
    'npm WARN node_modules/prettier\n' +
    'npm WARN   prettier@"npm:wp-prettier@2.2.1-beta-1" from @wordpress/scripts@19.2.1\n' +
    'npm WARN   node_modules/@wordpress/scripts\n' +
    'npm WARN     dev @wordpress/scripts@"*" from the root project\n' +
    'npm WARN   1 more (@wordpress/eslint-plugin)\n' +
    'npm WARN \n' +
    'npm WARN Could not resolve dependency:\n' +
    'npm WARN peer prettier@">=1.13.0" from eslint-plugin-prettier@3.4.1\n' +
    'npm WARN node_modules/eslint-plugin-prettier\n' +
    'npm WARN   eslint-plugin-prettier@"^3.3.0" from @wordpress/eslint-plugin@9.3.0\n' +
    'npm WARN   node_modules/@wordpress/eslint-plugin\n' +
    'npm ERR! code ERESOLVE\n' +
    'npm ERR! ERESOLVE unable to resolve dependency tree\n' +
    'npm ERR! \n' +
    'npm ERR! Found: acorn@7.4.1\n' +
    'npm ERR! node_modules/acorn\n' +
    'npm ERR!   acorn@"^7.4.0" from espree@7.3.1\n' +
    'npm ERR!   node_modules/espree\n' +
    'npm ERR!     espree@"^7.3.1" from eslint@7.32.0\n' +
    'npm ERR!     node_modules/eslint\n' +
    'npm ERR!       eslint@"^7.17.0" from @wordpress/scripts@19.2.1\n' +
    'npm ERR!       node_modules/@wordpress/scripts\n' +
    'npm ERR!         dev @wordpress/scripts@"*" from the root project\n' +
    'npm ERR!       15 more (@wordpress/eslint-plugin, eslint-plugin-markdown, ...)\n' +
    'npm ERR!     espree@"^7.3.0" from @eslint/eslintrc@0.4.3\n' +
    'npm ERR!     node_modules/@eslint/eslintrc\n' +
    'npm ERR!       @eslint/eslintrc@"^0.4.3" from eslint@7.32.0\n' +
    'npm ERR!       node_modules/eslint\n' +
    'npm ERR!         eslint@"^7.17.0" from @wordpress/scripts@19.2.1\n' +
    'npm ERR!         node_modules/@wordpress/scripts\n' +
    'npm ERR!         15 more (@wordpress/eslint-plugin, eslint-plugin-markdown, ...)\n' +
    'npm ERR!   peer acorn@"^6.0.0 || ^7.0.0 || ^8.0.0" from acorn-jsx@5.3.2\n' +
    'npm ERR!   node_modules/acorn-jsx\n' +
    'npm ERR!     acorn-jsx@"^5.3.1" from espree@7.3.1\n' +
    'npm ERR!     node_modules/espree\n' +
    'npm ERR!       espree@"^7.3.1" from eslint@7.32.0\n' +
    'npm ERR!       node_modules/eslint\n' +
    'npm ERR!         eslint@"^7.17.0" from @wordpress/scripts@19.2.1\n' +
    'npm ERR!         node_modules/@wordpress/scripts\n' +
    'npm ERR!         15 more (@wordpress/eslint-plugin, eslint-plugin-markdown, ...)\n' +
    'npm ERR!       1 more (@eslint/eslintrc)\n' +
    'npm ERR!   1 more (acorn-globals)\n' +
    'npm ERR! \n' +
    'npm ERR! Could not resolve dependency:\n' +
    'npm ERR! peerOptional acorn@"^8.5.0" from terser@5.10.0\n' +
    'npm ERR!   node_modules/terser-webpack-plugin\n' +
    'npm ERR!       dev @wordpress/scripts@"*" from the root project\n' +
    'npm ERR!     1 more (webpack)\n' +
    'npm ERR! \n' +
    'npm ERR! Fix the upstream dependency conflict, or retry\n' +
    'npm ERR! this command with --force, or --legacy-peer-deps\n' +
    'npm ERR! to accept an incorrect (and potentially broken) dependency resolution.\n' +
    'npm ERR! \n' +
    'npm ERR! See C:\Users\username\AppData\Local\npm-cache\eresolve-report.txt for a full report.\n' +
    '\n' +
    'npm ERR! A complete log of this run can be found in:\n' +
    'npm ERR!     C:\Users\username\AppData\Local\npm-cache\_logs\debug.log',
  failed: true,
  timedOut: false,
  isCanceled: false,
  killed: false
}
npm ERR! code 1
npm ERR! path D:\repos\ParentFolder\ProjectFolder\wp-content\plugins
npm ERR! command failed
npm ERR! command C:\WINDOWS\system32\cmd.exe /d /s /c wp-create-block my-first-block

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\username\AppData\Local\npm-cache\_logs\debug.log

在错误中它提到了诸如“修复上游依赖冲突”之类的东西,我认为这是问题的原因。我是 运行ning node v15.5.1,我也尝试安装 Docker 和 运行ning WLS with Ubuntu.

我的目标是能够为古腾堡开发我自己的块和模式,并将它们作为 WordPress 插件发布。

你能试试 npm install @wordpress/scripts --save-dev --legacy-peer-deps

这帮我解决了。