After upgrading to Nx 19.x when a node.js project has a build target configured to @nx/esbuild:esbuild with generatePackageJson: true, thirdParty: true, and references a local library (e.g. lib1) it fails to generate the package-lock, when removes the local library reference (run the lint --fix to remove from the package.json) it generates the package-lock successfully.
Expected Behavior
when the thirdParty: true only the external dependencies should be in the package.json.
app1 uses a function exported by lib1, therefore, the app1's package.json has the lib1 listed as dependency (automatically added by the eslint @nx/dependency-checks rule)
lib1 exports a simple function that uses lodash to capitalize a string value.
app2 uses the lodash directly instead of referencing the lib1.
When the build target is executed for the app1 project it fails with Original error: Pruned lock file creation failed. The following package was not found in the root lock file: @example/lib1@0.0.1
When the build target is executed for the app2 project it runs successfully and generates both package.json and lock file.
✔ 1/1 dependent project tasks succeeded [0 read from cache]
Hint: you can run the command with --verbose to see the full dependent project outputs
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
> nx run app1:build
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: Pruned lock file creation failed. The following package was not found in the root lock file: @example/lib1@0.0.1
Error: Pruned lock file creation failed. The following package was not found in the root lock file: @example/lib1@0.0.1
at /Users/lucasvieira/Projects/nx-workspaces/nx19-generate-lock/node_modules/.pnpm/nx@19.2.0_@swc-node+register@1.9.1_@swc+core@1.5.25/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:45:19
at Array.forEach (<anonymous>)
at normalizeDependencies (/Users/lucasvieira/Projects/nx-workspaces/nx19-generate-lock/node_modules/.pnpm/nx@19.2.0_@swc-node+register@1.9.1_@swc+core@1.5.25/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:31:42)
at pruneProjectGraph (/Users/lucasvieira/Projects/nx-workspaces/nx19-generate-lock/node_modules/.pnpm/nx@19.2.0_@swc-node+register@1.9.1_@swc+core@1.5.25/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:13:34)
at createLockFile (/Users/lucasvieira/Projects/nx-workspaces/nx19-generate-lock/node_modules/.pnpm/nx@19.2.0_@swc-node+register@1.9.1_@swc+core@1.5.25/node_modules/nx/src/plugins/js/lock-file/lock-file.js:166:79)
at updatePackageJson (/Users/lucasvieira/Projects/nx-workspaces/nx19-generate-lock/node_modules/.pnpm/@nx+js@19.2.0_@swc-node+register@1.9.1_@swc+core@1.5.25_@types+node@18.16.9_nx@19.2.0_typescript@5.4.5/node_modules/@nx/js/src/utils/package-json/update-package-json.js:48:61)
at copyPackageJson (/Users/lucasvieira/Projects/nx-workspaces/nx19-generate-lock/node_modules/.pnpm/@nx+js@19.2.0_@swc-node+register@1.9.1_@swc+core@1.5.25_@types+node@18.16.9_nx@19.2.0_typescript@5.4.5/node_modules/@nx/js/src/utils/package-json/index.js:26:53)
at esbuildExecutor (/Users/lucasvieira/Projects/nx-workspaces/nx19-generate-lock/node_modules/.pnpm/@nx+esbuild@19.2.0_@swc-node+register@1.9.1_@swc+core@1.5.25_@types+node@18.16.9_esbuild@0.19_wrczqmr3apewhx4aoqc7oc6dii/node_modules/@nx/esbuild/src/executors/esbuild/esbuild.impl.js:65:60)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async getLastValueFromAsyncIterableIterator (/Users/lucasvieira/Projects/nx-workspaces/nx19-generate-lock/node_modules/.pnpm/nx@19.2.0_@swc-node+register@1.9.1_@swc+core@1.5.25/node_modules/nx/src/utils/async-iterator.js:15:19)
——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
NX Successfully ran target build for project app1 and 1 task it depends on (3s)
Current Behavior
After upgrading to Nx 19.x when a node.js project has a
build
target configured to@nx/esbuild:esbuild
withgeneratePackageJson: true
,thirdParty: true
, and references a local library (e.g.lib1
) it fails to generate the package-lock, when removes the local library reference (run the lint --fix to remove from the package.json) it generates the package-lock successfully.Expected Behavior
when the
thirdParty: true
only the external dependencies should be in the package.json.As mentioned here: https://github.com/nrwl/nx/blob/9eebe4980a41715f9993ea72782d8280f5a721c3/packages/esbuild/src/executors/esbuild/esbuild.impl.ts#L96-L101
GitHub Repo
https://github.com/lucasvieirasilva/nx19-generate-lock-issue
Steps to Reproduce
In the https://github.com/lucasvieirasilva/nx19-generate-lock-issue repo, the project was created as follows:
esbuild
as bundler)esbuild
as bundler)app1
uses a function exported bylib1
, therefore, the app1's package.json has thelib1
listed as dependency (automatically added by the eslint@nx/dependency-checks
rule)lib1
exports a simple function that useslodash
to capitalize a string value.app2
uses thelodash
directly instead of referencing thelib1
.When the
build
target is executed for theapp1
project it fails withOriginal error: Pruned lock file creation failed. The following package was not found in the root lock file: @example/lib1@0.0.1
When the
build
target is executed for theapp2
project it runs successfully and generates both package.json and lock file.Nx Report
Failure Logs
Package Manager Version
pnpm 8.15.8
Operating System
Additional Information
No response