That script uses lots of WordPress packages, and WP Scripts makes sure it doesn’t put those in the built JS to stop it getting huge. Part of that is it creates a PHP file that just returns an array of all the things.
That code however has put []
in the dependencies spot, and tells WordPress that the script has zero dependencies and can be loaded in any order. As a result it’s loading before the @wordpress/core-data
library and has no idea what useEntityProps
means yet.
The other stuff works because it’s not running until your block is shown which happens later on. You might find that this error message looks different depending on the computer used, and the network conditions.
So to fix this, declare all the dependencies when it’s enqueued, something WP Scripts would normally do for you out of the box ( and something it probably did but was deleted to make way for a namespaced class ). It’s very likely WP Scripts is still set up to create a PHP file that lists all the dependencies on build to automate the process, if so include that file e.g. $dependencies = include( ....
( yes PHP files can return values just like functions, and include
has return values too! )