Error after installing module twice: Configuration object already exist I've followed How to create views programmatically in Drupal 8, but as I asked in this topic, my view doesn't appear in my list.

When I install my module twice (Enable -> Uninstall -> Enable), I have an error:


  Configuration object views.views.viewsname already exist


I also tried to import it directly in Drupal, copied the exact same code and this worked.
As the error says, the problem isn't with your module, but simply that the configuration your module is trying to create already exists in your installation.

You have two options to get it installed:


delete the configuration first, in the UI or programatically (How do I remove a configuration object from the active configuration?) and then add an enforced dependendency on your module, to make sure it is removed when your module is uninstalled. Note that you must first remove the config, the enforced dependency that removes your config only works once installed using the new definition.
Provide as optional config in config/optional instead of config/install. Optional config is different from other config in two ways: 


First, it is only installed when all the required dependencies exist. That is useful if you have optional integration with another module and if it is installed, provide some configuration for it. This even works if that other module is installed later on. Configuration with missing dependencies in config/install fails with an error as Drupal assumes your module will not work correctly if the config can not be installed.
Second, it will also be silently skipped if the config exists already, which is the relevant thing for your case. It will however also be silently skipped if the existing config just happens to be a view with the same name that is actually something else.