Support

Account

Home Forums Gutenberg Load JS in editor with block.json Reply To: Load JS in editor with block.json

  • Has anyone ran into an issue when using wp-scripts package that the {block}.asset.php file gets auto-generated but has blank dependencies? For example, I have an editor.asset.php file in my src block files with the following code:

    <?php
    return array(
        'dependencies' => array(
            'wp-element',
            'wp-blocks',
            'acf-input', // way to make block js wait for window.acf to exists
        )
    );

    However, when wp-scripts generates my build directory, that file is generated/copied, however the contents is now:

    <?php return array('dependencies' => array(), 'version' => '9f262c201bd7fd5a3679');

    I was digging into the actual code within the node package that generates the contents of this file, and it appears the if statement within this code block never runs because this.externalizedDeps is always just an empty set.

    const chunkDeps = new Set();
    
    			if ( injectPolyfill ) {
    				chunkDeps.add( 'wp-polyfill' );
    			}
    			const processModule = ( { userRequest } ) => {
    				if ( this.externalizedDeps.has( userRequest ) ) {
    					chunkDeps.add( this.mapRequestToDependency( userRequest ) );
    				}
    			};

    Any thoughts..?