nx: Pruned lock file creation failed. The following package was not found in the root lock file when using local packages
Current Behavior
nx/src/lock-file/project-graph-pruning.js throws an error if a service requires a package from our monorepo which can not be in the root’s package-lock.json. Since we install the required package from a registry, it will never be in the package-lock.
Expected Behavior
Can we use the version written in the required package’s package.json?
GitHub Repo
difficult setup
Steps to Reproduce
difficult setup
Nx Report
Node : 19.7.0
OS : darwin arm64
npm : 9.5.0
nx : 15.7.1
@nrwl/jest : 15.7.1
@nrwl/linter : 15.7.1
@nrwl/workspace : 15.7.1
@nrwl/cli : 15.7.1
@nrwl/devkit : 15.9.4
@nrwl/esbuild : 15.7.1
@nrwl/eslint-plugin-nx : 15.7.1
@nrwl/js : 15.7.1
@nrwl/node : 15.7.1
@nrwl/tao : 15.7.1
@nrwl/vite : 15.7.1
@nrwl/webpack : 15.7.1
typescript : 4.8.4
---------------------------------------
Community plugins:
@jscutlery/semver : 2.30.1
Failure Logs
Done compiling TypeScript files for project “engine-service”.
/Users/reventwork/Code/revent/backend/node_modules/nx/src/lock-file/project-graph-pruning.js:40
throw new Error(Pruned lock file creation failed. The following package was not found in the root lock file: ${packageName}@${versionRange});
^
Error: Pruned lock file creation failed. The following package was not found in the root lock file: @revent/configuration@1.0.7 at /Users/reventwork/Code/revent/backend/node_modules/nx/src/lock-file/project-graph-pruning.js:40:19 at Array.forEach (<anonymous>) at normalizeDependencies (/Users/reventwork/Code/revent/backend/node_modules/nx/src/lock-file/project-graph-pruning.js:26:42) at pruneProjectGraph (/Users/reventwork/Code/revent/backend/node_modules/nx/src/lock-file/project-graph-pruning.js:13:34) at createLockFile (/Users/reventwork/Code/revent/backend/node_modules/nx/src/lock-file/lock-file.js:122:75) at updatePackageJson (/Users/reventwork/Code/revent/backend/node_modules/@nrwl/js/src/utils/package-json/update-package-json.js:41:57) at /Users/reventwork/Code/revent/backend/node_modules/@nrwl/js/src/executors/tsc/tsc.impl.js:86:57 at Generator.next (<anonymous>) at fulfilled (/Users/reventwork/Code/revent/backend/node_modules/tslib/tslib.js:164:62) at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Package Manager Version
No response
Operating System
- macOS
- Linux
- Windows
- Other (Please specify)
Additional Information
No response
About this issue
- Original URL
- State: open
- Created 10 months ago
- Reactions: 1
- Comments: 16 (3 by maintainers)
This is still happening in 17.0.2
@AgentEnder these seem to originate from the last refactoring. Can you please look into it?
I may be getting something similar
The error I see is:
NX Report:
whatwg-url@5.0.0is found in the following deps in package-lock.json:OS: macOS
Try this setting project.json:
excludeLibsInPackageJson: true@meeroslav Thank you for your answer!
I did as you suggested and deleted the lock file and
./node_modulsbut that doesn’t resolve the issue.I also tried installing
whatwg-url@5.0.0and then a different dep fails.In fact, I tried doing the same multiple times but more deps have issues being pruned.
Hi all,
Based on your reported issues this is not something we can solve. The purpose of lock file pruning is to prune the existing lock file and isolate just the packages your project needs. We can’t come up with snapshots for packages that do not exist in the root lock file as that requires a round trip to the registry which beats the purpose of lock file pruning vs. built-in package manager install commands.
@paul-reventwork is there a reason your lock file does not contain @revent/configuration? How do you run tests against something that is missing its dependencies? It seems that you are doing something very custom in which case I would suggest skipping built-in lock file pruning and using
installdirectly to generate a lock file based on your needs.@gbanis your lock file mentions
whatwg-urlbut does not contain it - that package is never installed. If it was your lock file would have a key likenode_modules\whatwg-url. Since that dependency is not marked as optional, I would suspect that your lock file is broken. Try removing the lock file and node_modules and reinstalling them again.@KeithGillette your packages are out of sync as
nx reportsuggests. This could easily be the reason why things don’t work. Ensure all your packages are synchronized by runningnx migrate 16.8.1and check if the error is still there.@trekinbami same as @gbanis, check if the package is actually installed in your node_modules.
If you checked all the steps above:
Also getting a similar error on rebuilds following file changes after some recent dependency updates:
bl-2-2-1appears 4 times in our monorepository’spackage-lock.json.nx report