nx: `Target project does not exist` error on app restart

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:

 >  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:debug@2.6.9


   Error: Target project does not exist: npm:debug@2.6.9
    at validateCommonDependencyRules (/Users/artur/WebstormProjects/example-apps/nx-isolating-issue/node_modules/nx/src/project-graph/project-graph-builder.js:288:15)
    at validateDependency (/Users/artur/WebstormProjects/example-apps/nx-isolating-issue/node_modules/nx/src/project-graph/project-graph-builder.js:278:5)
    at ProjectGraphBuilder.addDependency (/Users/artur/WebstormProjects/example-apps/nx-isolating-issue/node_modules/nx/src/project-graph/project-graph-builder.js:165:9)
    at ProjectGraphBuilder.addStaticDependency (/Users/artur/WebstormProjects/example-apps/nx-isolating-issue/node_modules/nx/src/project-graph/project-graph-builder.js:82:14)
    at /Users/artur/WebstormProjects/example-apps/nx-isolating-issue/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:81:17
    at Array.forEach (<anonymous>)
    at traverseNode (/Users/artur/WebstormProjects/example-apps/nx-isolating-issue/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:78:36)
    at /Users/artur/WebstormProjects/example-apps/nx-isolating-issue/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:80:9
    at Array.forEach (<anonymous>)
    at traverseNode (/Users/artur/WebstormProjects/example-apps/nx-isolating-issue/node_modules/nx/src/plugins/js/lock-file/project-graph-pruning.js:78:36)

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

  1. generate a new integrated NX monorepository with the NestJS app
  2. set generatePackageJson: true for the app
  3. start the app in develop (watch) mode
  4. make modifications to trigger a restart

Nx Report

Node   : 20.6.1
   OS     : darwin-arm64
   npm    : 9.8.1

   nx                 : 16.8.1
   @nx/js             : 16.8.1
   @nx/jest           : 16.8.1
   @nx/linter         : 16.8.1
   @nx/workspace      : 16.8.1
   @nx/devkit         : 16.8.1
   @nx/eslint-plugin  : 16.8.1
   @nx/nest           : 16.8.1
   @nx/node           : 16.8.1
   @nrwl/tao          : 16.8.1
   @nx/webpack        : 16.8.1
   typescript         : 5.1.6

Failure Logs

No response

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: 11
  • Comments: 15 (2 by maintainers)

Most upvoted comments

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
        }
      }
    },
......

I can confirm I’m still seeing this in 17.0.2