New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@nrwl/nest - Generated package.json does not include @nestjs/platform-express
starting with nx 15.2.2
#13625
Comments
Also seen here. Just waiting on a final shakedown when deployed, but the build artefacts came out fine after importing the dependency statically:
|
Happening almost the same from same version When I think is the same issue, but let me know if this should be treat as an independent issue and I will create one. Thanks in advance |
This problem hit me, too. I wrote a Bash script as an ugly workaround (or quick hack) to be run inside a "node:18-bullseye" container image on Linux. In my case, both What this hack does is basically the following:
#!/bin/bash
nestjs_dir=dist/apps/api
if [ -d ${nestjs_dir} ]; then
wget https://github.com/stedolan/jq/releases/download/jq-1.6/jq-linux64
mv jq-linux64 jq
chmod u+x jq
input_file=${nestjs_dir}/package.json
platform_express_version=$(./jq -r '.dependencies."@nestjs/platform-express"' package.json)
class_transformer_version=$(./jq -r '.dependencies."class-transformer"' package.json)
echo patching ${input_file} with @nestjs/platform-expresss in version $platform_express_version
echo patching ${input_file} with class-transformer in version $class_transformer_version
cp ${input_file} api.tmp
./jq --arg platform_express_version "$platform_express_version" \
--arg class_transformer_version "$class_transformer_version" \
".dependencies += {\"@nestjs/platform-express\": \"$platform_express_version\", \"class-transformer\": \"$class_transformer_version\"}" api.tmp > ${input_file}
rm api.tmp
else
echo Nothing to do.
fi Maybe it'll help you in successfully building your app again. |
Update on this solution. It works fine. Short of any fix to the root cause, the simplest thing is just to put a static import of each missing package in your app entrypoint and then Nx will pick it up and emit it. The problem is very likely that Nx has stopped looking for dynamic imports, so we need to declare them. |
Also seeing this now on 15.3.3 (just with |
@Nick-Lucas, the solution you proposed works as a temporary workaround. The difference in Nx is that we have stopped adding optional peer dependencies to the production bundles. We will look into what is the best approach to solve this. @yharaskrik your issue is related, the |
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) |
I have different problem: I don’t use This is happening to me for some while, but I can’t which Nx versions are affected. I know that Should I open a separate issue for this? |
@tukusejssirs check my last comment. Do you have |
I have a similar problem, but i am missing nest/core instead. The project is a vanilla project without any added bells and whistles. Clean generated @nrwl/nest application. The generated package.json includes nestjs/common but not nestjs/core. any ideas how that could happen? E: nestjs/core is added in the main package.json, just for reference. I would really like to use the generated package.json functionality as it reduces my Docker images by almost 500mb For what its worth, the workaround with the static imports is working. But it is really undesirable from a dependency management perspective. |
We have just merged the improved lock file parsing and pruning, which is used for package.json generation. Hopefully, the new version solves it for you. Expect this fix in 15.7.0. |
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context. |
Current Behavior
From 15.2.2 onwards, using the
generatePackageJson
option in@nrwl/nest
projects will not include@nestjs/platform-express
in the generatedpackage.json
. As a result, when running the bundle with the generated dependencies only, Nest cannot start and prints an errorGenerated package.json:
Expected Behavior
For versions <=15.2.1, the
@nestjs/platform-express
dependency was included in the generatedpackage.json
. As a result, Nest was able to find the default HTTP driver.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
project.json
of the app to set"generatePackageJson": true
npx nx build
package.json
:cat dist/apps/*/package.json
To see the HTTP driver error:
node_modules
, otherwise node will find the missing module in the workspace root:rm -rf node_modules
cd dist/apps/* && npm i && node main.js
Nx Report
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 - #13438 - thinks the dependency is an optional peer dependency
The text was updated successfully, but these errors were encountered: