Migrating to v2
v2 is a focused redesign around clearer configuration, diagnostic errors and a lighter install. Most apps only need step 1.
1. Flatten enginesOptions
The nested block becomes top-level fields (the old shape still works with a deprecation warning):
NestDynamicTemplatesModule.forRoot({
engines: { template: ['njk'], language: ['html', 'mjml'] },
- enginesOptions: {
- filters: { formatDate },
- globalValues: { brandName: 'Acme' },
- template: { njk: { autoescape: true } },
- },
+ filters: { formatDate },
+ globals: { brandName: 'Acme' }, // renamed from globalValues
+ engineOptions: { template: { njk: { autoescape: true } } },
});2. engines now gates loading
In v1 the list was ignored — every engine loaded. In v2 only enabled engines are instantiated, so list every engine you use and install its peer. Rendering with a disabled engine throws TemplateEngineUnavailableError. The list is also replaced, not merged: template: ['hbs'] yields exactly ['hbs'].
3. Errors are restructured
| Removed (v1) | Use instead (v2) |
|---|---|
TemplateEngineError, TemplateLanguageError, TemplateLayoutError, TemplateContentError | TemplateRenderError (rich details, 422) |
TemplateValidationError | TemplateInputError (400) |
- Render failures are now 422 (were 500).
- Use
isTemplateError(err)anderr.code/err.details; the original error is onerr.cause. - Errors still extend their matching Nest exception, so
instanceof NotFoundExceptionetc. keep working.
4. TemplateConfigService is injectable
It was a global static; now inject it and use instance methods. The static setOptions/reset/hasConfig/get are gone.
5. render() no longer accepts inline content
Use renderContent() for raw strings. The renderEngine()/renderLanguage() service helpers were removed.
6. Behavior tweaks
render()returnssubject: string | null(was'').- HTML is a pass-through (no more
"Invalid HTML content"). - Markdown actually renders now (optional
markedpeer). - Only
isActive: truetemplates are resolved.
7. Dependencies
- Removed required peers:
@faker-js/faker,htmlparser2. - New optional peer:
marked(only if you enablemd). - No database schema changes.
The full changelog lives in the package CHANGELOG.