Open artursudnik opened 1 year ago
Got the same issue too while using yarn as a package manager.
Same issue; only mine is looking for node type Original error: Target project does not exist: npm:@types/node@20.5.7
Same issue but I see:
> 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 `npm install --package-lock-only` in your output folder it will regenerate the correct pruned lockfile.
Original error: Target project does not exist: npm:brace-expansion@2.0.1
Error: Target project does not exist: npm:brace-expansion@2.0.1
I am getting a similar issue after upgrading to 16.9.1 and 16.10.0. Issue is not on 16.4.0.
edit: also seeing this with 17.0.1
> 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: Target project does not exist: npm:is-stream@2.0.1
Error: Target project does not exist: npm:is-stream@2.0.1
at validateCommonDependencyRules (/workspaces/project-name/node_modules/.pnpm/nx@16.10.0_@swc-node+register@1.6.8_@swc+core@1.3.94/node_modules/nx/src/project-graph/project-graph-builder.js:323:15)
at validateDependency (/workspaces/project-name/node_modules/.pnpm/nx@16.10.0_@swc-node+register@1.6.8_@swc+core@1.3.94/node_modules/nx/src/project-graph/project-graph-builder.js:313:5)
at ProjectGraphBuilder.addDependency (/workspaces/project-name/node_modules/.pnpm/nx@16.10.0_@swc-node+register@1.6.8_@swc+core@1.3.94/node_modules/nx/src/project-graph/project-graph-builder.js:190:9)
at ProjectGraphBuilder.addStaticDependency (/workspaces/project-name/node_modules/.pnpm/nx@16.10.0_@swc-node+register@1.6.8_@swc+core@1.3.94/node_modules/nx/src/project-graph/project-graph-builder.js:89:14)
at /workspaces/project-name/node_modules/.pnpm/nx@16.10.0_@swc-node+register@1.6.8_@swc+core@1.3.94/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:81:17
at Array.forEach (<anonymous>)
at traverseNode (/workspaces/project-name/node_modules/.pnpm/nx@16.10.0_@swc-node+register@1.6.8_@swc+core@1.3.94/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:78:36)
at /workspaces/project-name/node_modules/.pnpm/nx@16.10.0_@swc-node+register@1.6.8_@swc+core@1.3.94/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:80:9
at Array.forEach (<anonymous>)
at traverseNode (/workspaces/project-name/node_modules/.pnpm/nx@16.10.0_@swc-node+register@1.6.8_@swc+core@1.3.94/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:78:36)
Still present in 17.0.2. This error causes build failures in watch mode after some unpredictable number of restarts, and it also prevents a successful build when running nx docker-build
from the app directory (e.g., apps/my-app
) without a lockfile already present. I'm working around this currently by copying the root lockfile into the app directory temporarily. Obviously not an ideal solution.
I can confirm I'm still seeing this in 17.0.2
This issue is also present on 17.1.2.
I can confirm that if I set generatePackageJson
to false
then the issue is gone. However that generated package json is needed for the docker image. I appear to be getting a successful build with the generatePackageJson
set to true
but I haven't done a full build and deploy on nx 17+.
@AgentEnder I think tracked down why this error is happening. It is because some dependencies append an @{version} to the end of the name, but this is not always reflected in the graph. My theory is it happens when the root lockfile has a dependency with different versions but the pruned lockfile only has 1 of those versions. I have not tracked down where nx determines to add the @{version} or not.
I was able to "fix" this in nx/src/project-graph/project-graph-builder
- validateCommonDependencyRules
by parsing the name and removing @{version} if it exists.
I just did this in the node_modules folder so its the js output instead of original ts source.
// nx/src/project-graph/project-graph-builder.js
function parseName(value) {
const lastAtIndex = value.lastIndexOf('@');
const colonIndex = value.indexOf(':');
if (lastAtIndex === -1 || lastAtIndex - colonIndex === 1) {
return value;
}
const name = value.substring(0, lastAtIndex);
return name
}
function validateCommonDependencyRules(d, { externalNodes, projects, fileMap }) {
if (!projects[d.source] &&
!externalNodes[d.source] &&
!projects[parseName(d.source)] &&
!externalNodes[parseName(d.source)]) {
throw new Error(`Source project does not exist: ${d.source}`);
}
if (!projects[d.target] &&
!externalNodes[d.target] &&
!('sourceFile' in d && d.sourceFile) &&
!externalNodes[parseName(d.target)]) {
throw new Error(`Target project does not exist: ${d.target}`);
}
.....
I would open a PR but this doesn't feel like the correct fix.
I have updated the isolated case to nx@17.1.2
@artursudnik Have you find any workaround around this issue ?
@fantoine Unfortunately not. I am just ignoring these annoying messages.
Same after upgrading NX to v17.2.4
I came across a workaround in another issue. I tried it out using @artursudnik nx-isolated-issue and it appears to fix it.
See this comment: https://github.com/nrwl/nx/issues/20421#issuecomment-1851882236
Basically just need to move generatePackageJson: true
to the production config. This should work unless you have a need to generatedPackageJson in development.
"build": {
"executor": "@nx/webpack:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
......
"generatePackageJson": false
},
"configurations": {
"development": {},
"production": {
"generatePackageJson": true
}
}
},
......
Still a problem in Nx v18.0.5.
The suggested workaround technically works but isn't relevant in my case. I actually need my package.json
to be generated in development mode as well.
Use case: I'm developing a vscode extension and vscode reads feature configuration from package.json
. As I develop or modify features, I need to make the relevant changes in my package.json
and I would like those to be reflected immediately, without relaunching the extension host.
Anyone managed to come up with a fix?
NX An error occurred 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 `npm install --package-lock-only` in your output folder it will regenerate the correct pruned lockfile.
Original error: Target project does not exist: npm:debug@2.6.9
Error: Target project does not exist: npm:debug@2.6.9
at validateCommonDependencyRules (C:\Path\To\Project\node_modules\nx\src\project-graph\project-graph-builder.js:323:15)
at validateDependency (C:\Path\To\Project\node_modules\nx\src\project-graph\project-graph-builder.js:313:5)
at ProjectGraphBuilder.addDependency (C:\Path\To\Project\node_modules\nx\src\project-graph\project-graph-builder.js:190:9)
at ProjectGraphBuilder.addStaticDependency (C:\Path\To\Project\node_modules\nx\src\project-graph\project-graph-builder.js:89:14)
at C:\Path\To\Project\node_modules\nx\src\plugins\js\lock-file\project-graph-pruning.js:81:17
at Array.forEach (<anonymous>)
at traverseNode (C:\Path\To\Project\node_modules\nx\src\plugins\js\lock-file\project-graph-pruning.js:78:36)
at C:\Path\To\Project\node_modules\nx\src\plugins\js\lock-file\project-graph-pruning.js:80:9
at Array.forEach (<anonymous>)
at traverseNode (C:\Path\To\Project\node_modules\nx\src\plugins\js\lock-file\project-graph-pruning.js:78:36)
chunk (runtime: main) main.js (main) 18.8 KiB (javascript) 670 bytes (runtime) [entry] [rendered]
webpack compiled successfully (0e3e969e157c6987)
Upgraded Nx to v18.2.1. Problem persists.
With the latest NX v19.0.3 the error is still there.
Im at nx v18.3.1 and it is still an issue, this workaround solves my issue
I came across a workaround in another issue. I tried it out using @artursudnik nx-isolated-issue and it appears to fix it. See this comment: #20421 (comment) Basically just need to move
generatePackageJson: true
to the production config. This should work unless you have a need to generatedPackageJson in development."build": { "executor": "@nx/webpack:webpack", "outputs": ["{options.outputPath}"], "defaultConfiguration": "production", "options": { ...... "generatePackageJson": false }, "configurations": { "development": {}, "production": { "generatePackageJson": true } } }, ......
Current Behavior
after setting
generatePackageJson: true
for a nodejs NestJS application I noticed that when it is started in watch mode, on every restart I am getting the following error:After that, it restarts correctly.
When building code nothing like this happens.
Expected Behavior
No error messages on restart
GitHub Repo
https://github.com/artursudnik/nx-isolated-issue
Steps to Reproduce
generatePackageJson: true
for the appNx Report
Failure Logs
No response
Package Manager Version
No response
Operating System
Additional Information
No response