WordPress / gutenberg

The Block Editor project for WordPress and beyond. Plugin is available from the official repository.
https://wordpress.org/gutenberg/
Other
10.35k stars 4.13k forks source link

`npx @wordpress/create-block` fails with "Error: Command failed with exit code 127" #28809

Closed waviaei closed 3 years ago

waviaei commented 3 years ago

Description

Used npx @wordpress/create-block to create a block, it fails. It will create package directories under node_modules/, but they are all empty inside.

Step-by-step reproduction instructions

Just run npx @wordpress/create-block

Expected behaviour

Creates block as per documented.

Note:

Some googling of "Error: Command failed with exit code 127" lead me to similar errors in Yarn package, where people suggesting "delete node_modules/ and do npm install again" -- this seem to solve though no sure why.

So I tried same, and this completed installation. Not sure why.

cd my-blocks
rm -rf node_modules/
npm install

Anyhow, npx @wordpress/create-block should just work.

Code snippet (optional)

npx @wordpress/create-block

Let's customize your block: ? The block slug used for identification (also the plugin and output folder name ): my-blocks ? The internal namespace for the block name (something unique for your products) : my-blocks ? The display title for your block: My Blocks ? The short description for your block (optional): Example block written with ES Next standard and JSX support – build step required. ? The dashicon to make it easier to identify your block (optional): smiley ? The category name to help users browse and discover your block: widgets ? The name of the plugin author (optional). Multiple authors may be listed using commas: waviaei ? The short name of the plugin’s license (optional): GPL-2.0-or-later ? A link to the full text of the license (optional): https://www.gnu.org/license s/gpl-2.0.html ? The current version number of the plugin: 0.1.0

Creating a new WordPress block in "my-blocks" folder.

Creating a "block.json" file.

Creating a "package.json" file.

Installing npm dependencies. It might take a couple of minutes...

Installing @wordpress/scripts package. It might take a couple of minutes...

Formatting JavaScript files. /Users/toru/.npm/_npx/0890e296436e9575/node_modules/execa/lib/error.js:59 error = new Error(message); ^

Error: Command failed with exit code 127: npm run format:js sh: wp-scripts: command not found npm ERR! code 127 npm ERR! path /Users/toru/Sites/sandbox/my-blocks npm ERR! command failed npm ERR! command sh -c wp-scripts format-js

npm ERR! A complete log of this run can be found in: npm ERR! /Users/toru/.npm/_logs/2021-02-07T03_19_19_705Z-debug.log

my-blocks@0.1.0 format:js wp-scripts format-js

at makeError (/Users/toru/.npm/_npx/0890e296436e9575/node_modules/execa/lib/error.js:59:11)
at handlePromise (/Users/toru/.npm/_npx/0890e296436e9575/node_modules/execa/index.js:114:26)
at processTicksAndRejections (node:internal/process/task_queues:93:5)
at async module.exports (/Users/toru/.npm/_npx/0890e296436e9575/node_modules/@wordpress/create-block/lib/init-wp-scripts.js:25:2)
at async module.exports (/Users/toru/.npm/_npx/0890e296436e9575/node_modules/@wordpress/create-block/lib/scaffold.js:96:3)
at async Command.<anonymous> (/Users/toru/.npm/_npx/0890e296436e9575/node_modules/@wordpress/create-block/lib/index.js:100:6) {

shortMessage: 'Command failed with exit code 127: npm run format:js', command: 'npm run format:js', exitCode: 127, signal: undefined, signalDescription: undefined, stdout: '\n> my-blocks@0.1.0 format:js\n> wp-scripts format-js\n', stderr: 'sh: wp-scripts: command not found\n' + 'npm ERR! code 127\n' + 'npm ERR! path /Users/toru/Sites/sandbox/my-blocks\n' + 'npm ERR! command failed\n' + 'npm ERR! command sh -c wp-scripts format-js\n' + '\n' + 'npm ERR! A complete log of this run can be found in:\n' + 'npm ERR! /Users/toru/.npm/_logs/2021-02-07T03_19_19_705Z-debug.log', failed: true, timedOut: false, isCanceled: false, killed: false } npm ERR! code 1 npm ERR! path /Users/toru/Sites/sandbox npm ERR! command failed npm ERR! command sh -c wp-create-block

npm ERR! A complete log of this run can be found in: npm ERR! /Users/toru/.npm/_logs/2021-02-07T03_19_19_766Z-debug.log

Below is the output doing deletion of node modules and doing npm install.

cd my-blocks my-blocks rm -rf node_modules ➜ my-blocks npm install npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated npm WARN deprecated fsevents@1.2.13: fsevents 1 will break on node v14+ and could be using insecure binaries. Upgrade to fsevents 2. npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address' npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi' npm WARN deprecated core-js@2.6.12: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.

added 949 packages, and audited 950 packages in 13s

40 packages are looking for funding run npm fund for details

7 low severity vulnerabilities

To address all issues, run: npm audit fix

Run npm audit for details.

Device information

waviaei commented 3 years ago

Actually, infact, something is still not right, because npm run build does not work.

npm run build

my-blocks@0.1.0 build wp-scripts build

sh: wp-scripts: command not found npm ERR! code 127 npm ERR! path /Users/toru/Sites/sandbox/my-blocks npm ERR! command failed npm ERR! command sh -c wp-scripts build

talldan commented 3 years ago

Hi @waviaei, sorry for the delay getting back to you, are you still experiencing the problem?

We discussed this issue in a slack triage session (https://wordpress.slack.com/archives/C02QB2JS7/p1620711271039900), and none of us could reproduce the problem, so I think it has since been solved.

There's now a new issue though, described in https://github.com/WordPress/gutenberg/issues/31361. That can be best worked around by using node 15 / npm 7, or by explicitly npm installing postcss in the project after it has been created.

Hope that helps. I'll close this issue now.

waviaei commented 3 years ago

@talldan Thank you for taking time in triaging the issue. I had a quick check, and same issue still occurred. However, update npm from 7.3 to 7.14 and it now seem to work. It does give Skipping "@wordpress/block-editor" npm dependency. error, but it now do build.

I am currently not actively using create-block so please keep the issue closed. Thanks!

markhowellsmead commented 2 years ago

This error occurred for me too: the solution was to run export NODE_ENV=development first. If the NODE_ENV isn't development, the npm install command doesn't install the development dependency @wordpress/scripts. cc @talldan.

multiplehats commented 5 months ago

export NODE_ENV=development

I searched the ENTIRE internet and I was going crazy, Years of experience with npm and pnpm. To find that this is the solution.

You're a god send this evening lol. Thank you!

giannis-dallas commented 5 months ago

What is the reason for this issue @markhowellsmead?

Shouldn't npx @wordpress/create-block work out of the box?

I get the same error even for simpler commands like: npx @wordpress/create-block@latest todo-list

markhowellsmead commented 5 months ago

Not sure, sorry. I haven’t looked at it for over two years and the issue was closed in 2021. The tech. has doubtlessly moved on considerably since then.

giannis-dallas commented 5 months ago

And yet, the issue still happens 🙂 Thank you for the quick reply!

waviaei commented 4 months ago

@giannis-dallas Not an issue with @wordpress/create-block, but my friend who develop themes using @wordpress/scripts/, wp-env, etc, had a weird situation where scripts do not build properly. It turns out that it was export NODE_ENV=development that was written into his bash or zsh file -- same as @markhowellsmead . He suspects it was seem to be added by node version manager e.g. nvm, n, nodenv. He is not sure which, as he was testing/swapping around few.

It explains why the issue happens to some people and not to everyone. I can't be sure, but if you use node version manager, check for update, settings, etc.

giannis-dallas commented 4 months ago

Thank you, it worths taking a deeper look

CodeBAou commented 2 months ago

Setting export NODE_ENV=development solved my problem, thank you very much @markhowellsmead

skorasaurus commented 2 months ago

still experienced this error using nvm (installed on a fresh ubuntu 22.04 system this week), node v22.4.0, and 4.46.0 create-block.

Solved by adding NODE_ENV=development to my .bashrc