HMR Block is already registered.

[ad_1]

I am trying to create a block with the help of @wordpress/scripts package. I tried this example but with HMR ( Hot Module Replacement ). Everything works fine except, my changes is not reflecting to the browser. It reloads the page but when i added the module.hot.accept() code, its through error – Block is already registered.

import { registerBlockType } from '@wordpress/blocks';
import json from './block.json';

const { name } = json;

// Register the block
registerBlockType( name, {
	edit: () => {
		return (
			<p style={{fontWeight: 'normal'}}>New Holla 2!</p>
		)
	},
	save: () => {
		return (
			<p>Holla Save!</p>
		)
	},
} );

if (module.hot) {
    module.hot.accept();
}

Can someone point the right direction, why i am getting this error or going to wrong way?

 

This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer