Unexpected error during import . . . plugin does not exist error on drush config import This is an issue I've had occasionally when trying to delete a plugin in a custom module.  In this example, once a filter format filter plugin has been enabled it's impossible to remove.  If you disable it and remove the plugin class from the codebase, it still shows up in the "filter.format.full_html.yml" config.

If you try to edit this file to remove the dependency and then do drush cim, you get an error:

Unexpected error during import with operation update for filter.format.basic_html: The &amp;quot;examplefilter&amp;quot; plugin does not exist.


How do you get rid of this dependency if it shows up in the config when disabled and you can't remove it from the config and import the config without getting a fatal error that the plugin is missing?
I was able to solve this with an update hook.  By deleting the config and then reimporting it this way, it doesn't trigger the unexpected error.  You need to run "drush updb" first, before "drush cim" for this to work.

use Drupal\Core\Config\FileStorage;

/**
 * Reimport filter.format.full_html and filter.format.basic_html.
 *
 * This is to remove the dependency on the examplefilter filter
 * which is being deleted.
 */
function mymodule_update_8003() {

  $config_ids = [
    'filter.format.full_html',
    'filter.format.basic_html',
  ];

  foreach ($config_ids as $config_id) {
    Drupal::configFactory()
      -&gt;getEditable($config_id)
      -&gt;delete();

    $config_path = config_get_config_directory('sync');
    $source = new FileStorage($config_path);
    $config_storage = \Drupal::service('config.storage');
    $config_storage-&gt;write($config_id, $source-&gt;read($config_id));
  }
}