JetBrains/intellij-community · error · ConfigurationException

Module '{0}' already exist in project. Please, specify anoth

Error message

Module '{0}' already exist in project. Please, specify another name.

What it means

Thrown by ModuleNameLocationComponent during new-module wizard validation when a module with the typed name already exists in the project. Module names must be unique per project, so the wizard blocks creation and asks for a different name.

Source

Thrown at java/idea-ui/src/com/intellij/ide/projectWizard/ModuleNameLocationComponent.java:346

  private void validateExistingModuleName() throws ConfigurationException {
    Project project = myWizardContext.getProject();
    if (project == null) return;

    final String moduleName = getModuleName();
    final Module module;
    final ProjectStructureConfigurable fromConfigurable = ProjectStructureConfigurable.getInstance(project);
    ModifiableModuleModel modifiableModel =
      fromConfigurable != null ? fromConfigurable.getContext().getModulesConfigurator().getModuleModel()
                               : null;
    if (modifiableModel != null) {
      module = modifiableModel.findModuleByName(moduleName);
    }
    else {
      module = ModuleManager.getInstance(project).findModuleByName(moduleName);
    }
    if (module != null) {
      throw new ConfigurationException(
        JavaUiBundle.message("module.name.location.dialog.message.module.already.exist.in.project", moduleName));
    }
  }

  private boolean validateModulePaths() throws ConfigurationException {
    String moduleName = getModuleName();
    String moduleFileDirectory = myModuleFileLocation.getText();
    if (moduleFileDirectory.isEmpty()) {
      throw new ConfigurationException(JavaUiBundle.message("module.name.location.dialog.message.enter.module.file.location"));
    }
    if (moduleName.isEmpty()) {
      throw new ConfigurationException(JavaUiBundle.message("module.name.location.dialog.message.enter.module.name"));
    }

    if (!ProjectWizardUtil.createDirectoryIfNotExists(JavaUiBundle.message("directory.module.file"), moduleFileDirectory,
                                                      myImlLocationChangedByUser)) {
      return false;
    }

View on GitHub (pinned to be881553f2)

Solutions

  1. Type a different, unique module name in the wizard's name field
  2. If the existing module is a leftover, delete or rename it first (File > Project Structure > Modules)
  3. When importing duplicated sources, give each import a distinct name prefix (e.g. 'copy-core')
  4. In plugin code, pre-check ModuleManager.getInstance(project).findModuleByName(name) == null before showing the step

Example fix

// before
String moduleName = "core"; // project already has a module 'core'
wizard.validate(); // ConfigurationException: module already exist

// after
String moduleName = "core2";
assert ModuleManager.getInstance(project).findModuleByName(moduleName) == null;
wizard.validate();
Defensive patterns

Strategy: validation

Validate before calling

String candidate = nameField.getText().trim();
Module existing = ModuleManager.getInstance(project).findModuleByName(candidate);
if (existing != null) {
  // pick another name / disable Finish before the wizard validates
}

Try / catch

try {
  component.validate();
} catch (ConfigurationException e) {
  // if duplicate-module message, auto-suffix: name + "2" and revalidate once
}

Prevention

When it happens

Trigger: Calling validate() on the module name/location step (or ModuleManager.findModuleByName / modifiableModel.findModuleByName returning non-null) with a name that duplicates an existing module; happens in both wizard mode and the Project Structure dialog when a ModifiableModuleModel is active.

Common situations: Importing a second copy of the same project/sources into one window (two modules named 'core'); Maven/Gradle subproject name collision after renaming; user types a name identical to an existing module; wizard pre-fills a default name that already exists.

Related errors


AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14). Data as JSON: /api/errors/a6498096269f9746. Report an issue: GitHub.