• Resolved lawrenceprak

    (@lawrenceprak)


    when adding a shortcode onto page, I am getting a javascript import error and an empty saveto-wishlist-item element presented.

    Uncaught SyntaxError: Cannot use import statement outside a module (at index.B3IUFaGN.js?ver=1780496387:1:170)

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Support Fitri Sinta

    (@supportfitri)

    Hello @lawrenceprak,

    Thanks for reporting this! We’ve been able to reproduce the issue and identify the cause.

    The error occurs when a JavaScript optimization or caching plugin is active on the site, such as WP Rocket, Autoptimize, LiteSpeed Cache, SiteGround Optimizer, or similar tools. These plugins can interfere with how our frontend script is loaded by stripping a required attribute that tells the browser to treat it as a modern JavaScript module.

    If you have a JS optimization plugin active, please try temporarily disabling features such as:

    • Combine JavaScript
    • Minify JavaScript
    • Defer JavaScript

    Then test again to see if the wishlist loads correctly. If it does, that confirms the conflict.

    We’ve already logged this as a bug, and a fix is currently in progress. We will let you know once the fix is available.

    In the meantime, if you let us know which caching or optimization plugin you’re using, we can provide more specific guidance on excluding our scripts from its optimization settings.

    Sorry for the trouble, and thanks again for reporting it.

    Thread Starter lawrenceprak

    (@lawrenceprak)

    I narrow it down to Wordfence Security. The error was it was out putting both type=”text/javascript” and type=”module”. In this cause we only need type=”module.”

    I was able to correct it via theme functions:

    add_filter('script_loader_tag', 'theme_force_clean_module_tag', 9999, 3);

    function theme_force_clean_module_tag($tag, $handle, $src) {

    // Only target your scripts (IMPORTANT)
    if (strpos($handle, 'saveto') === false && strpos($src, 'savetowishlist') === false) {
    return $tag;
    }

    // 1. Remove ANY existing type attribute (fixes duplicates)
    $tag = preg_replace('/\s*type=("|\').*?\1/', '', $tag);

    // 2. Force module cleanly
    $tag = str_replace('<script', '<script type="module"', $tag);

    return $tag;
    }
Viewing 2 replies - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.