• Resolved the_lar

    (@the_lar)


    I’m building a new Woocommerce site using roots/sage as my base theme (version 11) and when trying to add a product filter to a product archive page, I’m console errors such as:

    Uncaught TypeError: The specifier “@wordpress/interactivity” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”. product-filters.js:1:17

    I get 4 of these messages in the console and the filters whilst visible are not functioning. This only occurs in Firefox as far as I know, I have version 143.0.1. In Chrome everything is as it should be.

    I did come across this thread from a year go with a similar issue – https://ww.wp.xz.cn/support/topic/importmap-wordpress-interactivity/ where @becleung suggested it was because there is no priority set on the add_action in wp-includes/class-wp-script-modules.php. I have however tried adding the suggested code to my theme and whilst it gets rid of the original error, it introduces new ones:

    Uncaught TypeError: can't access property "symbol", r is undefined
    https://mtswheelsolutions.localhost/app/plugins/woocommerce/assets/client/blocks/woocommerce/product-filter-price.js?ver=b040f78c37f50f902e02:1
    product-filter-price.js:1:402

    Does anyone know how to get around this?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Moderator James Huff

    (@macmanx)

    I recommend getting in touch with WooCommerce’s support about this via https://woocommerce.com/my-account/contact-support/ if you have any of their paid WooCommerce products or https://ww.wp.xz.cn/support/plugin/woocommerce/ if you do not.

    It looks like the file product-filter-price.js is from a paid product, which I don’t have, so I can only guess, I can’t test my theory… but I’m guessing product-filter-price.js is being loaded too soon.

    Whatever “r” is, it’s probably defined by some script somewhere on your page, and product-filter-price.js needs to go after that.

    My script might be putting product-filter-price.js in the header when it’s supposed to be in the footer.

    So maybe you need to use wp_enqueue_script to put product-filter-price.js in the footer.

    Maybe something like this?

    add_action( 'wp_enqueue_scripts', 'enqueue_product_filter_price_after_r' );
    function enqueue_product_filter_price_after_r() {
    wp_enqueue_script('productfilterprice', plugins_url('woocommerce/assets/client/blocks/woocommerce/product-filter-price.js','woocommerce'), array(), '1.2.3', true);
    }

    You might have to adjust a few things. Such as the version number is probably not “1.2.3”, so put whatever the version number is, instead of “1.2.3”.

    • This reply was modified 7 months, 4 weeks ago by becleung. Reason: Edited to correct mistake in wp_enqueue_script
    Thread Starter the_lar

    (@the_lar)

    Thanks so much for having a look at this. @becleung joy with the script addition above though, adding that to my theme resulted in a new error:

    Uncaught SyntaxError: import declarations may only appear at top level of a module product-filter-price.js:1:1

    I’ll do what @macmanx suggested and raise an issue with Woocommerce!

    Looks like the script type needs to be specified as “module”. Adding this might help:

    function set_scripts_type_attribute( $tag, $handle, $src ) {
    if ( 'productfilterprice' === $handle ) {
    $tag = '<script type="module" src="'. $src .'"></script>';
    }
    return $tag;
    }
    add_filter( 'script_loader_tag', 'set_scripts_type_attribute', 10, 3 );
Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Firefox issue with @wordpress/interactivity module load’ is closed to new replies.