Optional peerDependencies are not declared in manifest
gabormagyar opened this issue · comments
Is there an existing issue for this?
- I have searched the existing issues
Current behavior
Using Yarn PnP I get the following error when trying to start a nest app that includes both @nestjs/terminus and @nestjs/microservices:
The "@nestjs/microservices" package is missing. Please, make sure to install the library
($ npm install @nestjs/microservices) to take advantage of MicroserviceHealthIndicator.
This happens because the require call in checkPackage.util.js:37 throws the following error reported by yarn PnP:
@nestjs/terminus tried to access @nestjs/microservices, but it isn't declared in its dependencies;
this makes the require call ambiguous and unsound.
To resolve this, @nestjs/microservices
, as well as any other optional dependencies should be declared as such by adding them to the peerDependencies field and marking them optional via the peerDependenciesMeta field in the package manifest.
In addition, the checkPackages
function in the same file swallows the error and logs the generic "missing" message which made debugging this matter rather difficult. I suggest rewriting this handling to either include the original error message, or to not catch the exception at all.
This code is present in @nestjs/common and @nestjs/schematics as well, so both of the above issues should probably be looked at in other places as well. I don't seem to be running into any other instances oif this issue at the moment, but I will open new issues as they happen. Feel free to open them anyway if you can see where else this can happen.
Workaround
Adding the following to the package's .yarnrc.yml
file fixes the issue:
packageExtensions:
"@nestjs/terminus@*":
peerDependencies:
"@nestjs/microservices": "*"
peerDependenciesMeta:
"@nestjs/microservices":
optional: true