Skip to content

bug: [readCachedProjectGraph] ERROR: No cached ProjectGraph is available after upgrading to NX v17.2.0 (@commitlint/config-nx-scopes) #3820

Closed
mkusztal/portfolioAboutMe
#165
@artursudnik

Description

@artursudnik

Expected Behavior

When using the @commitlint/config-nx-scopes with a typical configuration and executing commitlint on a clean local copy (empty nx cache), I would expect getProjects function to be executed without errors.

Current Behavior

I am getting the following error:

$ echo 'feat(backend): adding a feature' | npx commitlint -g commitlint.config.js
my-project/node_modules/@commitlint/cli/lib/cli.js:123
        throw err;
        ^

Error: [readCachedProjectGraph] ERROR: No cached ProjectGraph is available.

If you are leveraging \`readCachedProjectGraph()\` directly then you will need to refactor your usage to first ensure that
the ProjectGraph is created by calling \`await createProjectGraphAsync()\` somewhere before attempting to read the data.

If you encounter this error as part of running standard \`nx\` commands then please open an issue on https://github.com/nrwl/nx
    at readCachedProjectGraph (my-project/node_modules/nx/src/project-graph/project-graph.js:30:15)
    at Workspaces.readWorkspaceConfiguration (my-project/node_modules/nx/src/config/workspaces.js:21:122)
    at my-project/node_modules/@commitlint/config-nx-scopes/index.js:20:25
    at async scope-enum (my-project/commitlint.config.js:11:13)
    at async execute (my-project/node_modules/@commitlint/execute-rule/lib/index.js:11:19)
    at async Promise.all (index 11)
    at async load (my-project/node_modules/@commitlint/load/lib/load.js:61:20)
    at async main (my-project/node_modules/@commitlint/cli/lib/cli.js:189:20)

Affected packages

  • cli
  • core
  • prompt
  • config-angular

Possible Solution

No response

Steps to Reproduce

  1. Create a config file containing:
const {
  utils: {getProjects},
} = require('@commitlint/config-nx-scopes');

module.exports = {
  rules: {
    'scope-enum': async (ctx) => [
      2,
      'always',
      [
        ...(await getProjects(
          ctx,
          ({name, projectType}) =>
            !name.includes('e2e') && projectType == 'application'
        )),
      ],
    ],
  },
  // . . .
};
  1. npx nx reset
  2. echo 'feat(backend): adding a feature' | npx commitlint -g commitlint.config.js


### Context

_No response_

### commitlint --version

18.4.3

### git --version

git version 2.39.3 (Apple Git-145)

### node --version

v20.10.0

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions