nrwl / nx

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

fileMap is missing files after upgrade from v19.4.4 to v19.5.0 #28000

Open cainlevy opened 2 weeks ago

cainlevy commented 2 weeks ago

Current Behavior

After upgrading to ~v19.7.4~ v19.5.0, the @nx/dependency-checks rule believes that some of my packages have obsolete dependencies, while in fact the dependencies are referenced by existing code and are properly included with ~v18.3.1~ v19.4.4.

So far, the problem appears to be that the files importing the dependencies are no longer included in the file-map.json and thus are not parsed for dependencies. The pattern I am observing is that file-map.json does not include the contents of src/lib for any of my packages, and this will miss any dependencies referenced by those files.

NX ~v19~ v19.5.0 shows the following in fileMap.projectFileMap.validators:

        {
          "file": "packages/validators/src/index.ts",
          "hash": "3051616070451820306"
        },

NX ~v18~ v19.4.4 includes more:

        {
          "file": "packages/validators/src/index.ts",
          "hash": "3051616070451820306"
        },
        {
          "file": "packages/validators/src/lib/validators.spec.ts",
          "hash": "11102733480037190733"
        },
        {
          "file": "packages/validators/src/lib/validators.ts",
          "hash": "1428833592629210108",
          "deps": [
            "npm:date-fns"
          ]
        },

Expected Behavior

I expect the project-graph.json will reference all files in my packages and be aware of all dependencies used by those projects.

GitHub Repo

No response

Steps to Reproduce

  1. Install NX v19.5.0
  2. Create a TypeScript test package with packages/test/src/lib/file.ts
  3. Add a dependency to packages/test/package.json and import it from file.ts
  4. Run @nx/dependency-checks lint
  5. Observe that it believes the dependency to be obsolete
  6. Observe that packages/test/src/lib/file.ts is missing from .nx/workspace-data/project-graph.json and from .nx/workspace-data/file-map.json

Nx Report

Node           : 20.11.1
OS             : darwin-arm64
Native Target  : aarch64-macos
npm            : 10.2.4

nx                 : 19.7.4
@nx/js             : 19.7.4
@nx/jest           : 19.7.4
@nx/linter         : 19.7.4
@nx/eslint         : 19.7.4
@nx/workspace      : 19.7.4
@nx/cypress        : 19.7.4
@nx/devkit         : 19.7.4
@nx/esbuild        : 19.7.4
@nx/eslint-plugin  : 19.7.4
@nx/node           : 19.7.4
@nx/react          : 19.7.4
@nx/rollup         : 19.7.4
@nx/storybook      : 19.7.4
@nrwl/tao          : 19.7.4
@nx/vite           : 19.7.4
@nx/web            : 19.7.4
typescript         : 5.5.4
---------------------------------------
Registered Plugins:
@nx/rollup/plugin

Failure Logs

5:5  error  The "date-fns" package is not used by "validators" project  @nx/dependency-checks

Package Manager Version

No response

Operating System

Additional Information

No response

cainlevy commented 2 weeks ago

I bisected the problem by stepping through versions with the following commands:

npx nx migrate $version
npm i
rm -r .nx
npx nx reset
npx nx run validators:lint

The problem begins with 19.5.0. It does not exist with 19.4.4.

cainlevy commented 2 weeks ago

~Now I am getting the issue with a clean upgrade to 19.4.4 and even 19.0.8.~

~I can't figure out why this appears non-deterministic.~

cainlevy commented 2 weeks ago

My last comment was caused by confusion from a separate issue: https://github.com/nrwl/nx/issues/26675

When I control for this second bug, I once again see the fileMap problem appear with v19.5.0.