Skip to content
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

Nest/Pnpm cannot create isolated production bundles with generatePackageJson: true and externalDependencies: none #22778

Closed
1 of 4 tasks
rudfoss opened this issue Apr 11, 2024 · 2 comments

Comments

@rudfoss
Copy link

rudfoss commented Apr 11, 2024

Current Behavior

Building a Nest application with generatePackageJson: true in webpack.config.js produces a partial package.json file as output from a clean nx workspace missing the tslib dependency. From what I can read from the source code for the plugin the file webpack/src/plugins/generate-package-json-plugin.ts should in fact add the necessary external dependencies to the configuration, but debugging through it locally it fails to read the tsconfig file.

Using pnpm install --frozen-lockfile on the produced package.json file also fails because the pnpm-lock.yaml is also incomplete. I've worked around the issue by replacing the lockfile with my complete lockfile for the entire workspace, but that is not ideal.

In an attempt to avoid any bundling issues I've also tried to set externalDependencies: "none" in webpack.config.js which the documentation says is the default anyway, but that breaks both the build and serve targets due to failures when resolving modules.

Expected Behavior

Setting generatePackageJson: true should produce a complete package.json file with a valid pnpm-lock.yaml file.
Using externalDependencies: "none" should produce a single-file bundle without the need for installing modules at all if I understand things correctly.

GitHub Repo

https://github.com/rudfoss/nest-single-bundle

Steps to Reproduce

Reproduction repository provided with additional log details.

  1. Create a new nx workspace
  2. Install nest plugin
  3. Generate nest application
  4. Modify webpack.config.js by setting generatePackageJson: true and externalDependencies: "none".
  5. Try to build or serve the application.

Nx Report

NX   Report complete - copy this into the issue template

Node   : 20.9.0
OS     : win32-x64
pnpm   : 8.15.6

nx                 : 18.2.4
@nx/js             : 18.2.4
@nx/jest           : 18.2.4
@nx/linter         : 18.2.4
@nx/eslint         : 18.2.4
@nx/workspace      : 18.2.4
@nx/devkit         : 18.2.4
@nx/eslint-plugin  : 18.2.4
@nx/nest           : 18.2.4
@nx/node           : 18.2.4
@nrwl/tao          : 18.2.4
@nx/web            : 18.2.4
@nx/webpack        : 18.2.4
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin

Failure Logs

Installing using --frozen-lockfile:
pnpm i --frozen-lockfile
Lockfile is up to date, resolution step is skipped
 ERR_PNPM_LOCKFILE_MISSING_DEPENDENCY  Broken lockfile: no entry for '/iterare/1.2.1' in pnpm-lock.yaml

This issue is probably caused by a badly resolved merge conflict.
To fix the lockfile, run 'pnpm install --no-frozen-lockfile'.

----------------------

Running serve with externalDependencies "none"

pnpm exec nx run nest-app:serve

> nx run nest-app:serve:development

Build option outputFileName not set for nest-app. Using fallback value of dist\nest-app\main.js.

> nx run nest-app:build

> webpack-cli build --node-env=production

chunk (runtime: main) main.js (main) 1.93 MiB (javascript) 793 bytes (runtime) [entry] [rendered]

WARNING in ../node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nestjs/common/utils/load-package.util.js 9:39-59
Critical dependency: the request of a dependency is an expression

WARNING in ../node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/helpers/load-adapter.js
 9:39-63
Critical dependency: the request of a dependency is an expression

WARNING in ../node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/helpers/optional-require.js 6:39-59
Critical dependency: the request of a dependency is an expression

WARNING in ../node_modules/.pnpm/[email protected]/node_modules/express/lib/view.js 81:13-25
Critical dependency: the request of a dependency is an expression

ERROR in ../node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nestjs/common/pipes/validation.pipe.js 39:92-118
Module not found: Error: Can't resolve 'class-validator' in 'C:\projects\personal\nest-single-bundle\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@nestjs\common\pipes'

ERROR in ../node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nestjs/common/pipes/validation.pipe.js 43:94-122
Module not found: Error: Can't resolve 'class-transformer' in 'C:\projects\personal\nest-single-bundle\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@nestjs\common\pipes'

ERROR in ../node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@nestjs/common/serializer/class-serializer.interceptor.js 25:110-138
Module not found: Error: Can't resolve 'class-transformer' in 'C:\projects\personal\nest-single-bundle\node_modules\.pnpm\@[email protected][email protected][email protected]\node_modules\@nestjs\common\serializer'

ERROR in ../node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/nest-application.js 19:107-150
Module not found: Error: Can't resolve '@nestjs/websockets/socket-module' in 'C:\projects\personal\nest-single-bundle\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core'

ERROR in ../node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/nest-application.js 20:124-177
Module not found: Error: Can't resolve '@nestjs/microservices/microservices-module' in 'C:\projects\personal\nest-single-bundle\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core'

ERROR in ../node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/nest-application.js 123:120-152
Module not found: Error: Can't resolve '@nestjs/microservices' in 'C:\projects\personal\nest-single-bundle\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core'

ERROR in ../node_modules/.pnpm/@[email protected]_@[email protected]_@[email protected][email protected][email protected]/node_modules/@nestjs/core/nest-factory.js 57:120-152
Module not found: Error: Can't resolve '@nestjs/microservices' in 'C:\projects\personal\nest-single-bundle\node_modules\.pnpm\@[email protected]_@[email protected]_@[email protected][email protected][email protected]\node_modules\@nestjs\core'

webpack compiled with 7 errors and 4 warnings (8d686a702f6d8f6d)
Warning: command "webpack-cli build --node-env=production" exited with non-zero status code
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

 NX   Ran target build for project nest-app (5s)

   ×  1/1 failed
   √  0/1 succeeded [0 read from cache]

Build failed, waiting for changes to restart...

Package Manager Version

8.15.6

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

Copy link

This issue has been automatically marked as stale because it hasn't had any activity for 6 months.
Many things may have changed within this time. The issue may have already been fixed or it may not be relevant anymore.
If at this point, this is still an issue, please respond with updated information.
It will be closed in 21 days if no further activity occurs.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Oct 10, 2024
@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Oct 31, 2024
Copy link

github-actions bot commented Dec 1, 2024

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants