Skip to content

fix(zod-nestjs): tolerate @nestjs/swagger 11.4.3 exports map#268

Open
thmsbernard wants to merge 1 commit into
anatine:mainfrom
thmsbernard:fix/nestjs-swagger-11.4.3-exports-map
Open

fix(zod-nestjs): tolerate @nestjs/swagger 11.4.3 exports map#268
thmsbernard wants to merge 1 commit into
anatine:mainfrom
thmsbernard:fix/nestjs-swagger-11.4.3-exports-map

Conversation

@thmsbernard

Copy link
Copy Markdown

Summary

@nestjs/swagger@11.4.3 added a package.json#exports map that no longer exposes dist/services/schema-object-factory. The deep require inside patchNestjsSwagger now throws
ERR_PACKAGE_PATH_NOT_EXPORTED in plain Node, and webpack-bundled consumers (e.g. serverless-webpack Lambdas) crash at startup with Cannot find module '@nestjs/swagger/dist/services/schema-object-factory'.

11.4.0 - 11.4.2 do not have an exports field and work fine. The current peerDependencies range (^11.0.0) still allows 11.4.3, so a fresh npm install today pulls the broken combination.

Fixes #267

Fix

Resolve the factory file via the still-exported @nestjs/swagger/package.json, then load it by absolute path. Node's exports gating only applies to package-specifier resolution, not to absolute paths, so the
factory loads correctly without depending on any private surface of @nestjs/swagger.

The function signature is unchanged; existing callers that pass an explicit schemaObjectFactoryModule keep working as before.

Verification

Three-step proof in the same spec file, against the same Jest config:

Code @nestjs/swagger Result
main (unpatched) 11.4.3 FAIL — patchNestjsSwagger() throws
this PR 11.4.3 PASS
this PR 11.4.2 PASS (backward compat)

Tests

Added patch-nest-swagger.spec.ts covering:

  1. patchNestjsSwagger() with no arguments must not throw (regression guard).
  2. Explicit schemaObjectFactoryModule injection still works.

Drafted with the assistance of Claude (Anthropic). Reproduction, fix, and tests verified locally on Node 22 against @nestjs/swagger 11.4.2 and 11.4.3.

11.4.3 added a package.json "exports" field that no longer exposes
dist/services/schema-object-factory, so the deep require in
patchNestjsSwagger throws ERR_PACKAGE_PATH_NOT_EXPORTED in plain Node
and webpack-bundled consumers fail with webpackMissingModule.

Resolve the factory file via the still-exported package.json and load
it by absolute path: Node's exports gating only applies to package-
specifier resolution. No @nestjs/swagger internals are touched.
@nx-cloud

nx-cloud Bot commented May 19, 2026

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit 77663f6

Command Status Duration Result
nx affected:test --base=origin/main --codeCoverage ✅ Succeeded 24s View ↗
nx affected:lint --base=origin/main ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-19 08:26:28 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[zod-nestjs] patchNestjsSwagger breaks on @nestjs/swagger@11.4.3 due to new exports map

1 participant