fix(zod-nestjs): tolerate @nestjs/swagger 11.4.3 exports map#268
Open
thmsbernard wants to merge 1 commit into
Open
fix(zod-nestjs): tolerate @nestjs/swagger 11.4.3 exports map#268thmsbernard wants to merge 1 commit into
thmsbernard wants to merge 1 commit into
Conversation
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.
|
View your CI Pipeline Execution ↗ for commit 77663f6
☁️ Nx Cloud last updated this comment at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@nestjs/swagger@11.4.3added apackage.json#exportsmap that no longer exposesdist/services/schema-object-factory. The deeprequireinsidepatchNestjsSwaggernow throwsERR_PACKAGE_PATH_NOT_EXPORTEDin plain Node, and webpack-bundled consumers (e.g.serverless-webpackLambdas) crash at startup withCannot find module '@nestjs/swagger/dist/services/schema-object-factory'.11.4.0 - 11.4.2 do not have an
exportsfield and work fine. The currentpeerDependenciesrange (^11.0.0) still allows 11.4.3, so a freshnpm installtoday 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 thefactory loads correctly without depending on any private surface of
@nestjs/swagger.The function signature is unchanged; existing callers that pass an explicit
schemaObjectFactoryModulekeep working as before.Verification
Three-step proof in the same spec file, against the same Jest config:
@nestjs/swaggermain(unpatched)11.4.3patchNestjsSwagger()throws11.4.311.4.2Tests
Added
patch-nest-swagger.spec.tscovering:patchNestjsSwagger()with no arguments must not throw (regression guard).schemaObjectFactoryModuleinjection still works.Drafted with the assistance of Claude (Anthropic). Reproduction, fix, and tests verified locally on Node 22 against
@nestjs/swagger11.4.2 and 11.4.3.