Expected an identifier and instead saw ‘

If you use JSX in your code, then you need to build the script before using it on “standard” WordPress sites where JSX is not available.

So,

  • Either build the script..

  • Or (looking at your code, it’s probably easier to just) use (ES5 with) wp.element.createElement() and not JSX:

    var MyIcon = function () {
      var svg = createElement( 'svg', {},
        createElement( 'path', { d: 'M5 4v3h5.5v12h3V7H19V4z' } )
      );
      return createElement( wp.components.Icon, { icon: svg } );
    };
    

    And that would replace the following part:

    import { Icon } from '@wordpress/components';
    
    const MyIcon = () => (
        <Icon icon={ <svg><path d="M5 4v3h5.5v12h3V7H19V4z" /></svg> } />
    );