JetBrains/intellij-community · error · InvalidDataException
Module {name} has no content roots and will not be created.
Error message
Module {name} has no content roots and will not be created. What it means
Thrown by ModuleDescriptor.computeModuleFilePath() (InvalidDataException) when a module descriptor produced by project import has no content roots. The .iml path is derived from the first content root plus the module name; with zero content roots there is no basis for a path, so the importer refuses to fabricate a module file location.
Source
Thrown at java/idea-ui/src/com/intellij/ide/util/importProject/ModuleDescriptor.java:173
return builder.toString();
}
public void clearModuleDependencies() {
myDependencies.clear();
}
public void clearLibraryFiles() {
myLibraryFiles.clear();
}
public @NotNull String computeModuleFilePath() throws InvalidDataException {
final String name = getName();
final Set<File> contentRoots = getContentRoots();
if (!contentRoots.isEmpty()) {
return contentRoots.iterator().next().getPath() + File.separator + name + ModuleFileType.DOT_DEFAULT_EXTENSION;
}
else {
throw new InvalidDataException("Module " + name + " has no content roots and will not be created.");
}
}
}
View on GitHub (pinned to be881553f2)
Solutions
- Add at least one content root to the descriptor: descriptor.addContentRoot(VfsUtilCore.pathToUrl(dir)) before computing the path
- If importing, re-run import with correct source/root selection so the detector finds folders for every module
- Skip modules with no roots instead of materializing them (they would be useless in the model)
Example fix
// before ModuleDescriptor desc = new ModuleDescriptor(name, javaModuleType, contentEntryProvider); desc.computeModuleFilePath(); // InvalidDataException: no content roots // after ModuleDescriptor desc = new ModuleDescriptor(name, javaModuleType, contentEntryProvider); desc.addContentRoot(new File(baseDir, name)); desc.computeModuleFilePath(); // <root>/<name>/<name>.iml
Defensive patterns
Strategy: validation
Validate before calling
if (descriptor.getContentRoots().isEmpty()) {
descriptor.addContentRoot(moduleBaseDir); // or skip this descriptor entirely
}
String imlPath = descriptor.computeModuleFilePath(); Try / catch
try {
paths.add(descriptor.computeModuleFilePath());
} catch (InvalidDataException e) {
// log and skip the root-less module; do not abort the whole import
} Prevention
- Always addContentRoot(...) right after constructing a ModuleDescriptor
- Validate import descriptors in bulk before computing paths so one bad module does not stop the import
When it happens
Trigger: Building ModuleDescriptor objects during import-from-sources and calling computeModuleFilePath() on a descriptor whose getContentRoots() set is empty — e.g. addContentRoot() was never called or the detected roots list was empty.
Common situations: Importing a directory layout where a module's patterns match no folders; a third-party import plugin creates descriptors from a config that lists no roots; refactor leaves an intermediate descriptor unpopulated before path computation.
Related errors
- module.paths.validation.duplicate.content.error
- module.paths.validation.duplicate.source.root.error
- Module '{0}' already exist in project. Please, specify anoth
- Enter module file location
- Enter a module name
AI-assisted analysis of JetBrains/intellij-community@be881553f2 (2026-08-14).
Data as JSON: /api/errors/36dba98b157b40cf.
Report an issue: GitHub.