Unable to create a new module (module already exists) Intellij

Viewed 13385

I am trying to create a new module in my project. As soon as I specify the name of the module, Intellij throws "That this module already exists". After I exit the wizard it creates a directory with same module name but doesn't make it a module. I delete the directory and I perform "Invalidate Caches and Restart" but still the error persists.

module screenshot

enter image description here

6 Answers

I had this issue and went to .idea/modules.xml, found the path with the name I wanted, and deleted that line (just did ctrl+f with the name). After deleting that line and saving the file, I was able to create the module with that name.

You can try to perform the following actions:

  • Close the IDE and manually remove the module.
  • Remove .idea folder.
  • Open IDE and reimport the project.
  • Try adding the module once again according to official guide.

If the problem remains contact JetBrains support and attach a compressed log folder along with the project structure tree.

It is a caching issue . So try something on those lines

Invalidate cache and restart worked for me

But in case it doesn't you can try manually deleting .idea files or re-importing the project .

I had the same problem when I moved the code to a different directory. Detaching the workspaces, removing .idea, invalidating caches and so on did not help then.

For me what helped was this: Go to File -> Settings -> Project: workspace -> Project Structure. There you will see the all the projects you ever opened. And you will also see a button Add Content Root. There you can specify the new location of the (old) project.

If you are using Gradle and this is a multi-project layout, which is looks like it is, you shouldn't create modules directly in IntelliJ.

Rather, create the directory manually if it doesn't already exists, create a gradle.build[.kts] file in it if needed, and then add an import statement for it in settings.gradle[.kts]. Then just refresh the Gradle configuration in IntelliJ ("Reimport All Gradle Projects").

When this issue happens during import of existing project, then --close intellij ide --delete the project in explorer --clone it again --open intellij ide --and try to reimport

Related