Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Registering a block doesn't work when using the @wordpress/blocks package #18949

Closed
eddysims opened this issue Dec 5, 2019 · 1 comment
Closed
Labels
[Feature] Block API API that allows to express the block paradigm. [Status] Needs More Info Follow-up required in order to be actionable. [Type] Help Request Help with setup, implementation, or "How do I?" questions.

Comments

@eddysims
Copy link

eddysims commented Dec 5, 2019

Describe the bug

Registering a block doesn't work when using the @wordpress/blocks package

Additional context

My block won't register when using @wordpress/blocks. The following block registers

const { registerBlockType } = wp.blocks;

const blockStyle = {
	backgroundColor: '#900',
	color: '#fff',
	padding: '20px',
};

registerBlockType( 'gutenberg-examples/example-01-basic-esnext', {
	title: 'Example: Basic (esnext)',
	icon: 'universal-access-alt',
	category: 'layout',
	example: {},
	edit() {
		return <div style={ blockStyle }>Hello World, step 1 (from the editor).</div>;
	},
	save() {
		return <div style={ blockStyle }>Hello World, step 1 (from the frontend).</div>;
	},
} );

However changing to this, the block no longer registers

import { registerBlockType } from '@wordpress/blocks';

const blockStyle = {
	backgroundColor: '#900',
	color: '#fff',
	padding: '20px',
};

registerBlockType( 'gutenberg-examples/example-01-basic-esnext', {
	title: 'Example: Basic (esnext)',
	icon: 'universal-access-alt',
	category: 'layout',
	example: {},
	edit() {
		return <div style={ blockStyle }>Hello World, step 1 (from the editor).</div>;
	},
	save() {
		return <div style={ blockStyle }>Hello World, step 1 (from the frontend).</div>;
	},
} );
@gziolo gziolo added [Type] Help Request Help with setup, implementation, or "How do I?" questions. [Feature] Block API API that allows to express the block paradigm. labels Dec 5, 2019
@mcsf
Copy link
Contributor

mcsf commented Dec 6, 2019

This depends highly on your local build setup. If you are using a custom webpack config, these are some possible causes:

  1. @wordpress/blocks isn't defined as external.
  2. @wordpress/block is defined as an external, but not set up as a dependency.
  3. Unintended tree-shaking on @wordpress/blocks could lead to skipping store initialisation.

We might be able to help more if you're able to describe your build process and share any config.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Status] Needs More Info Follow-up required in order to be actionable. [Type] Help Request Help with setup, implementation, or "How do I?" questions.
Projects
None yet
Development

No branches or pull requests

4 participants