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

Lerna (powered by Nx) Cannot read properties of undefined (reading 'projects') #26975

Closed
1 of 4 tasks
lyj1994 opened this issue Jul 18, 2024 · 2 comments · Fixed by #26994
Closed
1 of 4 tasks

Lerna (powered by Nx) Cannot read properties of undefined (reading 'projects') #26975

lyj1994 opened this issue Jul 18, 2024 · 2 comments · Fixed by #26994
Assignees
Labels

Comments

@lyj1994
Copy link

lyj1994 commented Jul 18, 2024

Current Behavior

I use [email protected] [email protected].

TypeError: Cannot read properties of undefined (reading 'projects')
    at normalizeDependencyConfigProjects (/node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/utils.js:31:24)
    at normalizeDependencyConfigDefinition (/node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/utils.js:24:46)
    at /node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/utils.js:19:33
    at Array.flatMap (<anonymous>)
    at getDependencyConfigs (/node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/utils.js:19:13)
    at ProcessTasks.processTask (/node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/create-task-graph.js:68:68)
    at ProcessTasks.processTasks (/node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/create-task-graph.js:40:18)
    at createTaskGraph (/node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/create-task-graph.js:177:21)
    at createTaskGraphAndValidateCycles (/node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/run-command.js:65:63)
    at /node_modules/.pnpm/[email protected]/node_modules/nx/src/tasks-runner/run-command.js:88:27

I noticed that in the normalizeTargetDependencyWithStringProjects function, if projects='dependencies', it will directly return.
https://github.com/nrwl/nx/blob/master/packages/nx/src/tasks-runner/utils.ts#L198

export function normalizeTargetDependencyWithStringProjects(
  dependencyConfig: TargetDependencyConfig
): Omit<TargetDependencyConfig, 'projects'> & { projects: string[] } {
  if (typeof dependencyConfig.projects === 'string') {
    /** LERNA SUPPORT START - Remove in v20 */
    // Lerna uses `dependencies` in `prepNxOptions`, so we need to maintain
    // support for it until lerna can be updated to use the syntax.
    //
    // This should have been removed in v17, but the updates to lerna had not
    // been made yet.
    //
    // TODO(@agentender): Remove this part in v20
    if (dependencyConfig.projects === 'self') {
      delete dependencyConfig.projects;
    } else if (dependencyConfig.projects === 'dependencies') {
      dependencyConfig.dependencies = true;
      delete dependencyConfig.projects;
      return;
      /** LERNA SUPPORT END - Remove in v20 */
    } else {
      dependencyConfig.projects = [dependencyConfig.projects];
    }
  }
  return dependencyConfig as Omit<TargetDependencyConfig, 'projects'> & {
    projects: string[];
  };
}

This leads to a TypeError: Cannot read properties of undefined (reading 'projects') being thrown at the call site.
https://github.com/nrwl/nx/blob/master/packages/nx/src/tasks-runner/utils.ts#L72

const noStringConfig =
    normalizeTargetDependencyWithStringProjects(dependencyConfig);

  if (noStringConfig.projects) {
    dependencyConfig.projects = findMatchingProjects(
      noStringConfig.projects,
      graph.nodes
    );
  } else if (!noStringConfig.dependencies) {
    dependencyConfig.projects = [currentProject];
  }

Expected Behavior

Don't throw type error.

GitHub Repo

No response

Steps to Reproduce

Nx Report

NX   Report complete - copy this into the issue template

Node   : 20.14.0
OS     : darwin-arm64
pnpm   : 8.15.8

nx         : 19.4.3
lerna      : 8.1.3
@nrwl/tao  : 19.5.0

Failure Logs

No response

Package Manager Version

No response

Operating System

  • macOS
  • Linux
  • Windows
  • Other (Please specify)

Additional Information

No response

@tomalaforge
Copy link
Contributor

I have the same issue without being on a Lerna Project.
I upgraded my workspace to nx 19.5.0 and when I run the command
nx run-many --target=build

I have the same error:

 Cannot read properties of undefined (reading 'projects')

@FrozenPandaz FrozenPandaz added the scope: core core nx functionality label Jul 18, 2024
FrozenPandaz pushed a commit that referenced this issue Jul 22, 2024
…urn undefined (#26994)

<!-- Please make sure you have read the submission guidelines before
posting an PR -->
<!--
https://github.com/nrwl/nx/blob/master/CONTRIBUTING.md#-submitting-a-pr
-->

<!-- Please make sure that your commit message follows our format -->
<!-- Example: `fix(nx): must begin with lowercase` -->

<!-- If this is a particularly complex change or feature addition, you
can request a dedicated Nx release for this pull request branch. Mention
someone from the Nx team or the `@nrwl/nx-pipelines-reviewers` and they
will confirm if the PR warrants its own release for testing purposes,
and generate it for you if appropriate. -->

## Current Behavior
<!-- This is the behavior we have today -->

## Expected Behavior
<!-- This is the behavior we should expect with the changes in this PR
-->

## Related Issue(s)
<!-- Please link the issue being fixed so it gets closed when this is
merged. -->

Fixes #26975

(cherry picked from commit 188f0d8)
Copy link

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 24, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants