Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Editor encounters unexpected error seemingly at random #4043
I'm getting the following message when opening any post or page on my site: "The editor has encountered an unexpected error."
Steps to Reproduce (for bugs)
This issue has been plaguing me for awhile, but unfortunately I haven't been able to reliably reproduce it. I'm logging it anyway in the hopes that someone may know what's happening. Here's the required setup:
I haven't been able to either reliably reproduce this issue or figure out a way to get it working again once the error initially shows up.
Chrome 62.0.3202.94 on MacOS 10.12.6 and WordPress 4.9.1, Gutenberg 1.9.1.
The editor should show when I try to edit an existing post/page or add a new post/page.
I receive "The editor has encountered an unexpected error." when editing an existing post/page or when adding a new post/page.
Screenshots / Video
There's some sort of random issue with including a third party block that does not appear to be related to anything the block is doing. Everything can be working just fine one minute, and the next I'm getting the above error message for all posts/pages/CPTs, not just the one I added the block to. Undoing any development changes to the block that I may have made does not resolve the issue. Commenting out the line that enqueues the block's JS eliminates the error, but of course that isn't a proper solution.
I expect the root error is occurring at this line within the core media files:
I recently ran into a similar problem and ran into a very strange issue. After going through debugging I noticed that the issue came when I imported a module from lodash, which @billerickson module is doing as well (https://github.com/billerickson/BE-Subpages-Widget/blob/gutenberg/blocks/list-subpages/list-subpages.js). We are both importing like this:
The problem is that the babel-plugin-lodash plugin (https://www.npmjs.com/package/babel-plugin-lodash) was not installed. To fix this issue, all I did was install that babel plugin, and then add it to my
Either that or import the lodash modules like:
I have no idea why this is causing an issue in
Aha, I think it may be the case that Lodash's global
Closing as this is more of an issue with plugin authors overriding WordPress default globals. The above-mentioned workaround should work if you have a build system in place. Otherwise, the snippet below should also serve as a fix when registering your Lodash script, though I have not tested to confirm:
wp_enqueue_script( 'lodash', '...' ); wp_add_inline_script( 'lodash', 'window.lodash = _.noConflict();', 'after' );
(This would also mean you have to reference Lodash via