Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wordpress/script] wp-scripts build-blocks-manifest removes manifest file on start #69565

Open
3 of 6 tasks
samikeijonen opened this issue Mar 13, 2025 · 9 comments · May be fixed by #69578
Open
3 of 6 tasks

[wordpress/script] wp-scripts build-blocks-manifest removes manifest file on start #69565

samikeijonen opened this issue Mar 13, 2025 · 9 comments · May be fixed by #69578
Assignees
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended

Comments

@samikeijonen
Copy link
Contributor

Description

When using "start": "wp-scripts start && wp-scripts build-blocks-manifest" and running npm run start, blocks-manifest.php file is removed.

When using "build": "wp-scripts build && wp-scripts build-blocks-manifest" and running npm run build, blocks-manifest.php file is generated as it should.

Step-by-step reproduction instructions

  1. npx @wordpress/create-block@latest test-plugin
  2. cd test-plugin
  3. npm run build (blocks-manifest.php generated)
  4. npm run start (blocks-manifest.php deleted)

Screenshots, screen recording, code snippet

No response

Environment info

  • WordPress 6.7.2
  • 2025 theme
  • Node 22.14.0

Please confirm that you have searched existing issues in the repo.

  • Yes

Please confirm that you have tested with all plugins deactivated except Gutenberg.

  • Yes

Please confirm which theme type you used for testing.

  • Block
  • Classic
  • Hybrid (e.g. classic with theme.json)
  • Not sure
@samikeijonen samikeijonen added the [Type] Bug An existing feature does not function as intended label Mar 13, 2025
@itsseanl
Copy link

I'm having the same issue as of today. npm run build creates the manifest, but npm run start deletes it, and results in a site-wide critical error.

I'm running node v22.13.1, wordpress 6.7.2, and a bare-bones custom block theme.

@t-hamano
Copy link
Contributor

Thanks for the report. I was able to replicate it.

I think this discussion may be related to this issue. cc @felixarntz @gziolo

@t-hamano t-hamano added the [Tool] WP Scripts /packages/scripts label Mar 14, 2025
@itsseanl
Copy link

I took a look at that referenced discussion and did some digging (I suck at webpack), came up with a possible solution

in @wordpress/wp-scripts, you can update the webpack.config.js to include something like

const exec = require('child_process').exec;
const BlockManifest = {

	apply(compiler){
		compiler.hooks.afterEmit.tap('BlockManifest', (compilation) =>{
			process.stdout.write('ran after');
			exec(`wp-scripts build-blocks-manifest`, (error, stdout, stderr) => {
				if (error){
					console.error(`exec error: ${error}`);
				}
				console.log(`${stdout}`);
				if (stderr){
					console.error(`stderr: ${stderr}`);
				}
		});
		});
	}
};

and then add that to the plugins in ScriptConfig

here's my updated webpack.config.js, tested and working in my project

@2ndkauboy
Copy link
Contributor

We just ran into that issue at Cloudfest Hackathon. How about changing the start task like this?

"start": "wp-scripts start & wp-scripts build-blocks-manifest"

By using a single &, the seconds tasks always run, even if the first one is not successful (or in case of start never terminates).

@Hakira-Shymuy
Copy link

Hakira-Shymuy commented Mar 16, 2025

work around for it??

@2ndkauboy your method isnt work for me, it puts the manifest there but removes it 1 second after, at least in my case

@emergoncalves
Copy link

emergoncalves commented Mar 16, 2025

I solved this in the following way:

add this in package.json

"build": "wp-scripts build && wp-scripts build-blocks-manifest --output=dist/blocks-manifest.php",
"start": "wp-scripts start",
"build-manifest": "wp-scripts build-blocks-manifest --output=dist/blocks-manifest.php"

I edited the block initialization file to use the /dist folder:

function studiowp_topbar_block_block_init()
{
	if (function_exists('wp_register_block_types_from_metadata_collection')) { // Function introduced in WordPress 6.8.
		wp_register_block_types_from_metadata_collection(__DIR__ . '/dist', __DIR__ . '/dist/blocks-manifest.php');
	} else {
		if (function_exists('wp_register_block_metadata_collection')) { // Function introduced in WordPress 6.7.
			wp_register_block_metadata_collection(__DIR__ . '/dist', __DIR__ . '/dist/blocks-manifest.php');
		}
		$manifest_data = require __DIR__ . '/dist/blocks-manifest.php';
		foreach (array_keys($manifest_data) as $block_type) {
			register_block_type(__DIR__ . "/build/{$block_type}");
		}
	}
}

Use npm run build-manifest before using npm run start, and now the block-manifest.php file will be preserved because it will be in the /dist folder, and no longer in the /build folder which is renewed when a change is detected by the watch.

The build-blocks-manifest provides input and output parameters, and moving the file out of the build prevents it from being removed.

https://github.com/WordPress/gutenberg/tree/trunk/packages/scripts#build-blocks-manifest

@Hakira-Shymuy
Copy link

I solved this in the following way:

add this in package.json

"build": "wp-scripts build && wp-scripts build-blocks-manifest --output=dist/blocks-manifest.php",
  "build-manifest": "wp-scripts build-blocks-manifest --output=dist/blocks-manifest.php"

I edited the block initialization file to use the /dist folder:

function studiowp_topbar_block_block_init()
{
	if (function_exists('wp_register_block_types_from_metadata_collection')) { // Function introduced in WordPress 6.8.
		wp_register_block_types_from_metadata_collection(__DIR__ . '/dist', __DIR__ . '/dist/blocks-manifest.php');
	} else {
		if (function_exists('wp_register_block_metadata_collection')) { // Function introduced in WordPress 6.7.
			wp_register_block_metadata_collection(__DIR__ . '/dist', __DIR__ . '/dist/blocks-manifest.php');
		}
		$manifest_data = require __DIR__ . '/dist/blocks-manifest.php';
		foreach (array_keys($manifest_data) as $block_type) {
			register_block_type(__DIR__ . "/build/{$block_type}");
		}
	}
}

Use npm run build-manifest before using npm run start, and now the block-manifest.php file will be preserved.

The build-blocks-manifest provides input and output parameters, and moving the file out of the build prevents it from being removed.

the problem here is not with the build but with the start
on build everything works okay
but with npm start while webpack is watching it removes the manifest

@emergoncalves
Copy link

emergoncalves commented Mar 16, 2025

I solved this in the following way:
add this in package.json

"build": "wp-scripts build && wp-scripts build-blocks-manifest --output=dist/blocks-manifest.php",
  "build-manifest": "wp-scripts build-blocks-manifest --output=dist/blocks-manifest.php"

I edited the block initialization file to use the /dist folder:

function studiowp_topbar_block_block_init()
{
	if (function_exists('wp_register_block_types_from_metadata_collection')) { // Function introduced in WordPress 6.8.
		wp_register_block_types_from_metadata_collection(__DIR__ . '/dist', __DIR__ . '/dist/blocks-manifest.php');
	} else {
		if (function_exists('wp_register_block_metadata_collection')) { // Function introduced in WordPress 6.7.
			wp_register_block_metadata_collection(__DIR__ . '/dist', __DIR__ . '/dist/blocks-manifest.php');
		}
		$manifest_data = require __DIR__ . '/dist/blocks-manifest.php';
		foreach (array_keys($manifest_data) as $block_type) {
			register_block_type(__DIR__ . "/build/{$block_type}");
		}
	}
}

Use npm run build-manifest before using npm run start, and now the block-manifest.php file will be preserved.
The build-blocks-manifest provides input and output parameters, and moving the file out of the build prevents it from being removed.

the problem here is not with the build but with the start on build everything works okay but with npm start while webpack is watching it removes the manifest

It would be removed if it were in the /build folder, but since it will be in the /dist folder, it will remain preserved.

The solution I suggested (which I am currently using and is functioning correctly) aims to resolve the issue with npm run start, and not npm run build.

@felixarntz
Copy link
Member

I think the PR #69578 (based on @itsseanl's code above) is a cleaner solution, because it conditionally ties building the blocks manifest to the Webpack process. That way there's no need to have multiple commands in a single package.json script.

In the meantime, I think the above are reasonable workarounds until this has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Status] In Progress Tracking issues with work in progress [Tool] WP Scripts /packages/scripts [Type] Bug An existing feature does not function as intended
Projects
None yet
7 participants