@nrwl/nest - Generated package.json does not include `@nestjs/platform-express` starting with nx 15.2.2
See original GitHub issueCurrent Behavior
From 15.2.2 onwards, using the generatePackageJson option in @nrwl/nest projects will not include @nestjs/platform-express in the generated package.json. As a result, when running the bundle with the generated dependencies only, Nest cannot start and prints an error
ERROR [PackageLoader] No driver (HTTP) has been selected.
In order to take advantage of the default driver, please, ensure to install the "@nestjs/platform-express" package ($ npm install @nestjs/platform-express).
Generated package.json:
{
"name": "nx-nestjs-platform-reproducer",
"version": "0.0.1",
"dependencies": {
"@nestjs/common": "9.2.1",
"@nestjs/core": "9.2.1",
"reflect-metadata": "0.1.13",
"rxjs": "7.6.0",
"tslib": "2.4.1"
},
"main": "main.js"
}
Expected Behavior
For versions <=15.2.1, the @nestjs/platform-express dependency was included in the generated package.json. As a result, Nest was able to find the default HTTP driver.
{
"name": "nx-nestjs-platform-reproducer",
"version": "0.0.1",
"dependencies": {
"@nestjs/common": "9.2.1",
"@nestjs/core": "9.2.1",
"@nestjs/platform-express": "9.2.1",
"reflect-metadata": "0.1.13",
"rxjs": "7.6.0",
"tslib": "2.4.1"
},
"main": "main.js"
}
Github Repo
https://github.com/swcm-mpilz/nx-nestjs-platform-reproducer
Steps to Reproduce
Steps to reproduce are described in https://github.com/swcm-mpilz/nx-nestjs-platform-reproducer/blob/main/run-reproducer.sh. All that is required to reproduce the issue in a new repository:
npx create-nx-workspace nx-nestjs-platform-reproducer --preset=nest- Adapt
project.jsonof the app to set"generatePackageJson": true npx nx build- Inspect generated
package.json:cat dist/apps/*/package.jsonTo see the HTTP driver error: - Remove the workspace
node_modules, otherwise node will find the missing module in the workspace root:rm -rf node_modules - Run server with the generated dependencies:
cd dist/apps/* && npm i && node main.js
Nx Report
Node : 16.18.1
OS : linux x64
npm : 8.19.2
nx : 15.2.4
@nrwl/angular : Not Found
@nrwl/cypress : Not Found
@nrwl/detox : Not Found
@nrwl/devkit : 15.2.4
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : 15.2.4
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 15.2.4
@nrwl/js : 15.2.4
@nrwl/linter : 15.2.4
@nrwl/nest : 15.2.4
@nrwl/next : Not Found
@nrwl/node : 15.2.4
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/rollup : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : Not Found
@nrwl/web : Not Found
@nrwl/webpack : 15.2.4
@nrwl/workspace : 15.2.4
typescript : 4.8.4
---------------------------------------
Local workspace plugins:
---------------------------------------
Community plugins:
Failure Logs
[Nest] ERROR [PackageLoader] No driver (HTTP) has been selected. In order to take advantage of the default driver, please, ensure to install the "@nestjs/platform-express" package ($ npm install @nestjs/platform-express).
Additional Information
Probably showing up now because the algorithm introduced in 15.2.2 - https://github.com/nrwl/nx/pull/13438 - thinks the dependency is an optional peer dependency
Issue Analytics
- State:
- Created 10 months ago
- Reactions:3
- Comments:7 (3 by maintainers)
Top Related StackOverflow Question
Also seen here. Just waiting on a final shakedown when deployed, but the build artefacts came out fine after importing the dependency statically:
I think the solution is to consider root package json on how to treat optional peer dependencies - if they are added as a dependency in the root, then it will be resolved and mapped equally in the generated package.json.
Otherwise, we ignore it (to avoid bringing all kinds of unnecessary peer dependencies to generated package.json)