@nrwl/nest - Generated package.json does not include `@nestjs/platform-express` starting with nx 15.2.2

See original GitHub issue

Current 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.json of the app to set "generatePackageJson": true
  • npx nx build
  • Inspect generated package.json: cat dist/apps/*/package.json To 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:closed
  • Created 10 months ago
  • Reactions:3
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Nick-Lucascommented, Dec 5, 2022

Also seen here. Just waiting on a final shakedown when deployed, but the build artefacts came out fine after importing the dependency statically:

import '@nestjs/platform-express'
1reaction
meeroslavcommented, Dec 21, 2022

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)

Read more comments on GitHub >

github_iconTop Results From Across the Web

fix(core): consult root package.json when resolving peer deps ...
Currently, we ignore all optional peer dependencies when generating package.json. Unfortunately, packages such as nest (requires optional ...
Read more >
Nx missing dependencies on generated package.json
I'm using @nrwl/webpack , so the pluginsConfig worked for me without adding the two build options. – JoshuaCWebDeveloper. Nov 2 at 22:12. Add...
Read more >
Project Configuration - Nx
Both package.json and project.json files are located in each project's folder. Nx merges the two files to get each project's configuration. The following ......
Read more >
npm-install - npm Docs
Description. This command installs a package and any packages that it depends on. If the package has a package-lock, or an npm shrinkwrap...
Read more >
The Symbols In Your package.json File - Moving Forward
I have often been confused by the symbols in the package.json file. ... the package dependencies, and it is not always clear what...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found