Search code examples
wordpresswordpress-gutenberggutenberg-blocks

Gutenberg block throwing error after upgrade from 3.6.2 to 3.7.0


I created a block which pulls content from a CPT. I had no errors and everything worked correctly within the Gutenberg editor until I upgraded from Gutenberg 3.6.2 to 3.7.0. I went through the 3.7.0 changelog and nothing looked questionable at first glance.

Error thrown in console:

TypeError: Cannot read property 'models' of undefined

Relevant code:

// Create model and collection for custom post type.
var SwiftModule = wp.api.models.Post.extend({
    urlRoot: wpApiSettings.root + wpApiSettings.versionString + 'modules',
    defaults: {
        type: 'modules'
    }
});
var SwiftModules = wp.api.collections.Posts.extend({
    url: wpApiSettings.root + wpApiSettings.versionString + 'modules',
    model: SwiftModule
});

Any ideas? Thanks in advance.


Solution

  • I discovered that 'wp-api' is no longer enqueued in versions > 3.6.2 of the Gutenberg plugin. Everything is working nicely again after running wp_enqueue_script( 'wp-api' ); in my own code.