nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.49k stars 2.34k forks source link

nx fails to prune lock file when there are packages installed from url #22854

Open Luke265 opened 6 months ago

Luke265 commented 6 months ago

Current Behavior

when building an app with generatePackageJson enabled, nx fails to prune lock file if there are any packages that has peer dependencies and are installed from url eg; https://registry.npmjs.org/bootstrap/-/bootstrap-5.3.3.tgz?test

Edit: It also drops https:// from the generated package.json when it should not.

Expected Behavior

nx should be able to prune lock file when there are packages with peer dependencies installed from url

GitHub Repo

https://github.com/Luke265/nx-prune-issue

Steps to Reproduce

  1. pnpm i
  2. nx run issue:build

Nx Report

Node   : 21.2.0
OS     : win32-x64
pnpm   : 8.15.4

nx (global)        : 18.1.1
nx                 : 18.3.0
@nx/js             : 18.3.0
@nx/jest           : 18.3.0
@nx/eslint         : 18.3.0
@nx/workspace      : 18.3.0
@nx/eslint-plugin  : 18.3.0
@nx/node           : 18.3.0
@nrwl/tao          : 18.1.1
@nx/web            : 18.3.0
@nx/webpack        : 18.3.0
typescript         : 5.4.5
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin
---------------------------------------
The following packages should match the installed version of nx
  - @nrwl/tao@18.1.1

To fix this, run `nx migrate nx@18.3.0`

Failure Logs

NX   An error occured while creating pruned lockfile

Please open an issue at `https://github.com/nrwl/nx/issues/new?template=1-bug.yml` and provide a reproduction.
To prevent the build from breaking we are returning the root lock file.
If you run `pnpm install --lockfile-only` in your output folder it will regenerate the correct pruned lockfile.

Original error: Cannot read properties of undefined (reading '0')

TypeError: Cannot read properties of undefined (reading '0')
    at C:\dev\nx-prune-issue\node_modules\.pnpm\nx@18.3.0_@swc-node+register@1.8.0_@swc+core@1.3.107\node_modules\nx\src\plugins\js\lock-file\pnpm-parser.js:209:85
    at Array.forEach (<anonymous>)
    at C:\dev\nx-prune-issue\node_modules\.pnpm\nx@18.3.0_@swc-node+register@1.8.0_@swc+core@1.3.107\node_modules\nx\src\plugins\js\lock-file\pnpm-parser.js:202:47
    at Array.forEach (<anonymous>)
    at mapRootSnapshot (C:\dev\nx-prune-issue\node_modules\.pnpm\nx@18.3.0_@swc-node+register@1.8.0_@swc+core@1.3.107\node_modules\nx\src\plugins\js\lock-file\pnpm-parser.js:200:7)
    at stringifyPnpmLockfile (C:\dev\nx-prune-issue\node_modules\.pnpm\nx@18.3.0_@swc-node+register@1.8.0_@swc+core@1.3.107\node_modules\nx\src\plugins\js\lock-file\pnpm-parser.js:138:18)
    at createLockFile (C:\dev\nx-prune-issue\node_modules\.pnpm\nx@18.3.0_@swc-node+register@1.8.0_@swc+core@1.3.107\node_modules\nx\src\plugins\js\lock-file\lock-file.js:142:60)
    at C:\dev\nx-prune-issue\node_modules\.pnpm\@nx+webpack@18.3.0_@swc-node+register@1.8.0_@swc+core@1.3.107_@types+node@18.16.20_nx@18.3.0__c4b6sipvyw5wbykwvm3pl6bexa\node_modules\@nx\webpack\src\plugins\generate-package-json-plugin.js:39:138
    at fn (C:\dev\nx-prune-issue\node_modules\.pnpm\webpack@5.91.0_@swc+core@1.3.107_webpack-cli@5.1.4\node_modules\webpack\lib\Compilation.js:486:10)
    at _next0 (eval at create (C:\dev\nx-prune-issue\node_modules\.pnpm\tapable@2.2.1\node_modules\tapable\lib\HookCodeFactory.js:33:10), <anonymous>:11:1)

Package Manager Version

No response

Operating System

Additional Information

No response

Luke265 commented 2 months ago

I have updated the provided repo nx dependencies 18.3.0 to 19.5.7, it appears that the error has been resolved. However, the imported library is now being omitted from the pruned package.json and pnpm-lock.yaml files.