Package Exports
Readme
nestjs-esm-fix
Patch Nestjs app ESM bundles to make them work RHRN
Problem
openapi
is not defined. https://github.com/nestjs/swagger/issues/1450
__decorate([
Post('event-unsafe-batch'),
HttpCode(200),
openapi.ApiResponse({ status: 200, type: String }),
__param(0, Body()),
__param(1, Req()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object, Object]),
__metadata("design:returntype", Promise)
], EventUnsafeController.prototype, "logEventBatch", null);
- openapi / class-validator DTOs are referenced by
require
API.
export class CspReportDto {
static _OPENAPI_METADATA_FACTORY() {
return { timestamp: { required: false, type: () => Object }, 'csp-report': { required: true, type: () => require("./csp.dto.js").CspReport } };
}
}
Solution
Old good monkey patching.
Install
yarn add -D nestjs-esm-fix
Usage
CLI
nestjs-esm-fix target/**/*.js
Option | Description | Default |
---|---|---|
--openapi-var |
Inject openapi variable. Set --no-openapi-var to disable. |
true |
--openapi-type-ref |
Replace type: () => require statements with import . |
true |
JS API
import {fix} from 'nestjs-esm-fix'
await fix({
cwd: '.',
target: 'target/**/*.js',
openapiVar: true,
openapiTypeRef: true,
})