What's wrong with my code to overwrite a block template?
You can create a directory called templates/ in your modules root. Place your template here.

Now let Drupal know you store the template in your module. in your_module.module add this function:

function YOUR_MODULE_theme($existing, $type, $theme, $path) {
  return array(
    'block__my_module' =&gt; array(
      'render element' =&gt; 'elements',
      'template' =&gt; 'block--my-module',
      'base hook' =&gt; 'block'
    )
  );
}


Finally be careful about where you place your twig file and what you name it. Create a templates directory in your module directory, and replace the _ in the theme function name with -: mymodule-block.html.twig

Don´t forget to clear the cache.



According to answer written by Nicensin in this post: Drupal 8 custom block (module) create twig template file