Skip to main content
Version: 4.x

EXP4002: Controller is in no module

Raised as an error, in every environment. The application does not start.

A class decorated with @controller was loaded, and none of the modules given to configContainer() lists it.

ReportController is decorated with @controller, and no module given to configContainer() lists it.
Why: an application serves the controllers its modules list. Until 4.3 every controller that was loaded was served, so this one's routes would now answer 404.
Fix: add it to a module, as in CreateModule([ReportController]), and give that module to configContainer(). If it is loaded but not meant to be served here, say so with configContainer(modules, { controllers: "listed" }). To serve every loaded controller as before, use { controllers: "discovered" }.
Code: EXP4002

Since 4.4.0 an application serves the controllers its modules list, and only those. Earlier releases served every controller whose file was loaded, listed or not. The start is refused, and the controller is not just left out, because leaving it out would turn its routes into 404s with nothing to say why.

Fix​

Pick the one that matches what you meant.

The controller belongs to this application. List it in a module, and give the module to configContainer():

class App extends AppExpress {
private readonly container = this.configContainer([
CreateModule([UserController, ReportController]),
]);
}

A module that is created and never given to configContainer() lists nothing as far as the application is concerned.

The controller is loaded but is not this application's. This happens when one process loads the controllers of more than one application: a test file that builds two applications, or a package that exports several controllers from one file. Say that the list is the whole story:

this.configContainer(modules, { controllers: "listed" });

The application serves the listed controllers and leaves any other out, without complaint.

You want what 4.3 did. Serve every loaded controller, listed or not:

this.configContainer(modules, { controllers: "discovered" });

expressots check reports this error with its code, so it can be caught in CI before a deploy. See check.

All codes are listed under Error responses.