user14487566
user14487566

Reputation:

Gutenberg cannot seem to find TextControl

I have include @wordpress/components in my build. (I ran npm install wordpress/components and see it in package.json)

I import the TextControl thus: import {TextControl} from "@wordpress/components";

But at this line I see in the console: Uncaught TypeError: Cannot read properties of undefined (reading 'TextControl')

I am using wordpress-scripts package. Obviously I am missing a step.

What might it be?!

Upvotes: 0

Views: 664

Answers (1)

user14487566
user14487566

Reputation:

There were various problems but the main one I was not loading the dependencies that the wp-scripts build puts into a file with the name pluginname.asset.php. For example;

<?php return array('dependencies' => array('wp-components', 'wp-element'), 'version' => '123');

and in your wp_enqueue_script script call you have to send these dependencies as a parameter.

wp_enqueue_script('name', 'path.js', $script_asset['dependencies'], $script_asset['version']);

It looks like Gutenberg uses this to decide which bits of itself to load. They are not included the built js file.

Upvotes: 2

Related Questions