How can I fix the "Deleted and replaced configuration entity" error during configuration import? I am currently running into a config import error and it seems like it has something to do with field collections:

Finalizing configuration synchronization.                                                                                                                                                                                                                                                                                                                        


The import failed due for the following reasons:                                                                                                                                                                                                                                                                                                                

Deleted and replaced configuration entity "field_collection.field_collection.field_lives_around"


I just started yesterday with this project and created tons of fields and configurations, no custom code at all for now. Any idea what could go wrong?

The field collection contains an list (text) and an geolocation field (https://www.drupal.org/project/geolocation)
The error happens when entity you are trying to create already exists. Or the data changed while config import was in progress. See: ConfigImporter.php/checkOp().


  If the target already exists, use the entity storage to delete it again, if is a simple config, delete it directly.


Running import twice may help, but obviously not at the same time, otherwise, you probably need to remove that field manually and try again.

This could be a bug of the module, as normally modules should have the following condition in place, e.g.

 /**
  * Implements hook_ENTITY_TYPE_insert().
  */
 function hook_ENTITY_TYPE_insert(RoleInterface $role) {
   if (\Drupal::isConfigSyncing()) {
     // Do not change data while config import in progress.
     return;
   }
   // ...
 }


Related bug: The group_roles field gets created too early during configuration sync.



Few hints:


In case you don't need the particular import, you can use Config Ignore to ignore it.
Try exporting the config first, then import again.
Try importing config individually first, file by file by using Drupal Console, e.g.

drupal config:import:single --file=$PWD/config/sync/config_ignore.settings.yml