Skip to content

feat(core): accept module metadata as the root module - #18523

Merged
kamilmysliwiec merged 1 commit into
masterfrom
feat/core-factory-module-metadata
Nov 16, 2026
Merged

kamilmysliwiec merged 1 commit into
masterfrom
feat/core-factory-module-metadata

Conversation

@kamilmysliwiec

Copy link
Copy Markdown
Member

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

The root module passed to NestFactory has to be a class (or a dynamic module with a module class), so even the smallest app needs a decorated module class:

@Module({ controllers: [AppController] })
class AppModule {}

const app = await NestFactory.create(AppModule);

Issue Number: N/A

What is the new behavior?

NestFactory.create(), createApplicationContext() and createMicroservice() also accept plain module metadata:

const app = await NestFactory.create({ controllers: [AppController] });
  • IEntryNestModule gains ModuleMetadata. A plain object without module or forwardRef (or a promise of one) is treated as metadata.
  • Nest applies @Module(metadata) to a new AppModule class per call, the same way Test.createTestingModule() builds its root module. Unknown keys are rejected with the usual "Invalid property … passed into the @module() decorator" error, which also catches passing a module namespace object (await import('./app.module')) by mistake.
  • The root module shows up as AppModule in logs and the devtools graph.

It's meant as a shorthand for small apps: middleware (configure()) and lifecycle hooks on the root module still need a module class.

Does this PR introduce a breaking change?

  • Yes
  • No

IEntryNestModule is a public type and its union is wider now, so outside code that narrows it exhaustively could see new type errors.

Other information

Docs for docs.nestjs.com to follow.

NestFactory.create(), createApplicationContext() and
createMicroservice() now take plain module metadata, such as
{ controllers: [AppController] }, in place of a root module class.
Nest applies @module() to a new AppModule class, the same way
Test.createTestingModule() builds its root module, so unknown keys
are rejected as usual.
@kamilmysliwiec
kamilmysliwiec merged commit fc06905 into master Nov 16, 2026
5 checks passed
ofri-peretz added a commit to ofri-peretz/eslint that referenced this pull request Nov 18, 2026
NestJS 12.5.1 (nestjs/nest#18523) accepts module metadata as the root
module, so NestFactory.create({ imports: [JwtModule.register(...)] })
registers JwtModule in main.ts with no *.module.ts. require-expiration
read only module files and missed it. It now reads main.ts and
bootstrap.ts as well.

Also kills the rule's 8 surviving mutants (5 by test, 2 equivalent
conditionals removed), locks nestjs-security's project scan to root
metadata in main.ts, and advances the NestJS release cursor.

Intent: docs/intents/nestjs-nest-v12.5.1-root-module-metadata

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant