nrwl / nx

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

"An error occured while creating pruned lockfile" #28937

Open pct-tploeger opened 1 week ago

pct-tploeger commented 1 week ago

Current Behavior

I get the same error this issue mentions: #26296

I also got the message to create a ticket here. The same situation as the above mentioned issue applies: I have a node app that auto-reloads and throws the error pasted below. Only difference is, that its a different package that seems to be at fault here.

Expected Behavior

No error messages.

GitHub Repo

No response

Steps to Reproduce

1.

Nx Report

Node           : 20.18.0
OS             : linux-x64
Native Target  : x86_64-linux
npm            : 10.8.2

nx                 : 20.0.6
@nx/js             : 20.0.6
@nrwl/js           : 19.8.10
@nx/jest           : 20.0.6
@nx/linter         : 19.8.10
@nx/eslint         : 20.0.6
@nx/workspace      : 20.0.6
@nrwl/workspace    : 19.8.10
@nx/angular        : 20.1.0
@nrwl/angular      : 19.8.10
@nx/cypress        : 20.0.6
@nx/devkit         : 20.1.0
@nrwl/devkit       : 19.8.10
@nx/eslint-plugin  : 20.0.6
@nx/node           : 20.1.0
@nrwl/tao          : 19.8.10
@nx/web            : 20.0.6
@nrwl/web          : 19.8.10
@nx/webpack        : 20.0.6
@nrwl/webpack      : 19.8.10
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/webpack/plugin
@nx/eslint/plugin
@nx/jest/plugin
@nx/cypress/plugin
---------------------------------------
Community plugins:
@spartan-ng/cli : 0.0.1-alpha.366
---------------------------------------
Local workspace plugins:
@<redacted>/<redacted>

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 `npm install --package-lock-only` in your output folder it will regenerate the correct pruned lockfile.

Original error: Target project does not exist: npm:finalhandler@1.3.1

Error: Target project does not exist: npm:finalhandler@1.3.1
    at validateCommonDependencyRules (/workspace/node_modules/nx/src/project-graph/project-graph-builder.js:323:15)
    at validateDependency (/workspace/node_modules/nx/src/project-graph/project-graph-builder.js:314:5)
    at ProjectGraphBuilder.addDependency (/workspace/node_modules/nx/src/project-graph/project-graph-builder.js:191:9)
    at ProjectGraphBuilder.addStaticDependency (/workspace/node_modules/nx/src/project-graph/project-graph-builder.js:90:14)
    at /workspace/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:80:17
    at Array.forEach (<anonymous>)
    at traverseNode (/workspace/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:77:36)
    at /workspace/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:69:9
    at Array.forEach (<anonymous>)
    at addNodesAndDependencies (/workspace/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:66:37)

Package Manager Version

No response

Operating System

Additional Information

I have logged the output of the external nodes in the same way the error above does, where I get a similar output:

{
  source: 'npm:express',
  target: 'npm:finalhandler@1.3.1',
  type: 'static',
  sourceFile: undefined
} {
 ...
  'npm:finalhandler': {
    type: 'npm',
    name: 'npm:finalhandler',
    data: {
      version: '1.3.1',
      packageName: 'finalhandler',
      hash: 'sha512-6BN9trH7bp3qvnrRyzsBz+g3lZxTNZTbVO2EV1CS0WIcDbawYVdYvGflME/9QP0h0pYlCDBCTjYa9nZzMDpyxQ=='
    }
  },
 ...
} {} { projectFileMap: {}, nonProjectFiles: [] }

When running npm ls finalhandler I get a different result as the issue mentioned above:

@<redacted>/source@0.0.0 /workspace
├─┬ @11ty/eleventy@1.0.2
│ └─┬ browser-sync@2.29.3
│   └─┬ connect@3.6.6
│     └── finalhandler@1.1.0
└─┬ @nx/webpack@20.0.6
  └─┬ express@4.21.1
    └── finalhandler@1.3.1

Here is no type package mentioned, but it has two different versions aswell.

paustint commented 7 hours ago

Seems similar to #27571

Also getting the same issue - the error happens when trying to re-build after a file changes when using the serve command

I was on 20.1.2 and tried upgrading to see if that would resolve the issue.

We were using @nx/esbuild and we switched to @nx/webpack because we have some static files that we modify often and @nx/esbuild does not auto-restart and I could not find a way to watch these files.

The serve command is using @nx/js:node

Node           : 20.14.0
OS             : darwin-arm64
Native Target  : aarch64-macos
yarn           : 1.22.22

nx                 : 20.1.3
@nx/js             : 20.1.3
@nx/jest           : 20.1.3
@nx/eslint         : 20.1.3
@nx/workspace      : 20.1.3
@nx/devkit         : 20.1.3
@nx/esbuild        : 20.1.3
@nx/eslint-plugin  : 20.1.3
@nx/node           : 20.1.3
@nx/playwright     : 20.1.3
@nx/react          : 20.1.3
@nx/vite           : 20.1.3
@nx/web            : 20.1.3
@nx/webpack        : 20.1.3
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/playwright/plugin
 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.

Original error: Target project does not exist: npm:escape-string-regexp@1.0.5

Error: Target project does not exist: npm:escape-string-regexp@1.0.5
    at validateCommonDependencyRules (/Users/me/dev/company/frontend/node_modules/nx/src/project-graph/project-graph-builder.js:323:15)
    at validateDependency (/Users/me/dev/company/frontend/node_modules/nx/src/project-graph/project-graph-builder.js:314:5)
    at ProjectGraphBuilder.addDependency (/Users/me/dev/company/frontend/node_modules/nx/src/project-graph/project-graph-builder.js:191:9)
    at ProjectGraphBuilder.addStaticDependency (/Users/me/dev/company/frontend/node_modules/nx/src/project-graph/project-graph-builder.js:90:14)
    at /Users/me/dev/company/frontend/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:80:17
    at Array.forEach (<anonymous>)
    at traverseNode (/Users/me/dev/company/frontend/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:77:36)
    at /Users/me/dev/company/frontend/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:79:9
    at Array.forEach (<anonymous>)
    at traverseNode (/Users/me/dev/company/frontend/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:77:36)

There is a different dependency mentioned each time

Here is our project definition:

{
  "name": "service-name",
  "$schema": "../node_modules/nx/schemas/project-schema.json",
  "sourceRoot": "service-name/src",
  "projectType": "application",
  "tags": ["server"],
  "targets": {
    "build": {
      "executor": "@nx/webpack:webpack",
      "outputs": ["{options.outputPath}"],
      "defaultConfiguration": "production",
      "options": {
        "target": "node",
        "compiler": "tsc",
        "outputPath": "service-name/dist",
        "main": "service-name/src/main.ts",
        "tsConfig": "service-name/tsconfig.app.json",
        "assets": [
          "service-name/src/assets",
          {
            "glob": "**/*",
            "input": "service-name/templates",
            "output": "templates"
          }
        ],
        "webpackConfig": "service-name/webpack.config.js",
        "generatePackageJson": true
      },
      "configurations": {
        "development": {},
        "production": {
          "generateLockfile": true,
          "esbuildOptions": {
            "sourcemap": false,
            "outExtension": {
              ".js": ".js"
            }
          }
        }
      }
    },
    "serve": {
      "executor": "@nx/js:node",
      "defaultConfiguration": "development",
      "dependsOn": [],
      "options": {
        "buildTarget": "service-name:build",
        "runBuildTargetDependencies": false
      },
      "configurations": {
        "development": {
          "buildTarget": "service-name:build:development"
        },
        "production": {
          "buildTarget": "service-name:build:production"
        }
      }
    },
    "lint": {
      "executor": "@nx/eslint:lint"
    },
    "test": {
      "executor": "@nx/jest:jest",
      "outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
      "options": {
        "jestConfig": "service-name/jest.config.ts"
      }
    },
    "docker-build": {
      "dependsOn": ["build"],
      "command": "docker build -f service-name/Dockerfile . -t service-name"
    }
  }
}