Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 of 4 tasks
artursudnik opened this issue Dec 9, 2023 · 8 comments · Fixed by #3855 · May be fixed by mkusztal/portfolioAboutMe#165

Comments

@artursudnik
Copy link

artursudnik commented Dec 9, 2023

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
@artursudnik artursudnik added the bug label Dec 9, 2023
@artursudnik artursudnik changed the title Error: [readCachedProjectGraph] ERROR: No cached ProjectGraph is available after upgrading to NX v17.2.0 (@commitlint/config-nx-scopes) bug: [readCachedProjectGraph] ERROR: No cached ProjectGraph is available after upgrading to NX v17.2.0 (@commitlint/config-nx-scopes) Dec 9, 2023
@morozovamv
Copy link

I have the same issue, I tried different node version - no success.

@artursudnik
Copy link
Author

The same issue after upgrading to v17.2.3.

@artursudnik
Copy link
Author

There is a workaround for this:

const {
  utils: { getProjects },
} = require('@commitlint/config-nx-scopes');
const {
  createProjectGraphAsync,
} = require('nx/src/project-graph/project-graph');

module.exports = {
  rules: {
    'scope-enum': async (ctx) => [
      2,
      'always',
      [...(await getProjectsWrapper(ctx)), 'deps'],
    ],
  },
};

/**
 * This is a workaround for https://github.com/conventional-changelog/commitlint/issues/3820
 * remove this after it is fixed.
 */
async function getProjectsWrapper(ctx) {
  await createProjectGraphAsync();

  return getProjects(ctx, ({ name, projectType }) => {
    return projectType === 'application' || projectType === 'library';
  });
}

@artursudnik
Copy link
Author

Looks like the above is problematic. commitlint hangs when createProjectGraphAsync() is executed in a daemon process.

@artursudnik
Copy link
Author

artursudnik commented Dec 19, 2023

This is a fixed workaround:

const {
  utils: { getProjects },
} = require('@commitlint/config-nx-scopes');

const {
  createProjectGraphAsync,
} = require('nx/src/project-graph/project-graph');

process.env.NX_DAEMON = 'false';

module.exports = {
  rules: {
    'scope-enum': async (ctx) => [
      2,
      'always',
      [...(await getProjectsWrapper(ctx)), 'deps'],
    ],
  },
};

async function getProjectsWrapper(ctx) {
  await createProjectGraphAsync();

  return await getProjects(ctx, ({ name, projectType }) => {
    return projectType === 'application' || projectType === 'library';
  });
}

@morozovamv
Copy link

morozovamv commented Dec 20, 2023

@artursudnik Thanks for your fix, it worked, but our "version" command dropped all versions to 0.1.0, I'm not sure if it is connected somehow 😬

@artursudnik
Copy link
Author

@morozovamv I am not sure what "version" you mean...

@morozovamv
Copy link

morozovamv commented Dec 21, 2023

@artursudnik I created a discussion jscutlery/semver#759

UPD: @escapedcat sorry, clicked wrong suggestion when replied

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
3 participants