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

TypeError: Cannot read properties of undefined (reading 'defaultProject') #14592

Closed
jonsoku-dev opened this issue Jan 25, 2023 · 9 comments
Closed

Comments

@jonsoku-dev
Copy link

Current Behavior

    calculateDefaultProjectName(cwd, projects, nxJson) {
        console.log(nxJson)
        const relativeCwd = this.relativeCwd(cwd);
        if (relativeCwd) {
            const matchingProject = Object.keys(projects.projects).find((p) => {
                const projectRoot = projects.projects[p].root;
                return (relativeCwd == projectRoot ||
                    relativeCwd.startsWith(`${projectRoot}/`));
            });
            if (matchingProject)
                return matchingProject;
        }
        return nxJson.defaultProject
    }

TypeError: Cannot read properties of undefined (reading 'defaultProject')

CalculateDefaultProjectName generates an error when nxJson is undefined.

Expected Behavior

I think, it will be...

    calculateDefaultProjectName(cwd, projects, nxJson) {
        console.log(nxJson)
        const relativeCwd = this.relativeCwd(cwd);
        if (relativeCwd) {
            const matchingProject = Object.keys(projects.projects).find((p) => {
                const projectRoot = projects.projects[p].root;
                return (relativeCwd == projectRoot ||
                    relativeCwd.startsWith(`${projectRoot}/`));
            });
            if (matchingProject)
                return matchingProject;
        }
        return nxJson?.defaultProject ?? "";
    }

Github Repo

No response

Steps to Reproduce

  1. npm publish via ngx-deploy-npm

Nx Report

Node : 18.12.1
   OS   : darwin arm64
   pnpm : 7.18.1
   
   nx : 15.6.0
   @nrwl/angular : Not Found
   @nrwl/cypress : 15.6.0
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.6.0
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.6.0
   @nrwl/expo : Not Found
   @nrwl/express : Not Found
   @nrwl/jest : 15.6.0
   @nrwl/js : 15.6.0
   @nrwl/linter : 15.6.0
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : Not Found
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.6.0
   @nrwl/react-native : Not Found
   @nrwl/rollup : Not Found
   @nrwl/schematics : Not Found
   @nrwl/storybook : 15.6.0
   @nrwl/web : 15.6.0
   @nrwl/webpack : 15.6.0
   @nrwl/workspace : 15.6.0
   @nrwl/vite : Not Found
   typescript : 4.9.4
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:
         @jscutlery/semver: 2.29.3
         lerna: 6.4.1
         ngx-deploy-npm: 4.3.10

Failure Logs

No response

Additional Information

No response

@patzj
Copy link

patzj commented Jan 25, 2023

Try to use the latest nx version in your project dependencies.

@FrozenPandaz
Copy link
Collaborator

Can you please provide a github repo we can use to reproduce the issue?

@matheushf
Copy link

matheushf commented Jan 31, 2023

Downgrading to "nx": "15.0.3" fixed it for me

@FrozenPandaz It was a fresh integrated-repo install for me, just added a react-app with the nx generator

@miguelmoreba
Copy link

miguelmoreba commented Feb 6, 2023

I'm experiencing this as well.

For me, it only happens during the first run of

npx nx affected --base=last-release --target=version --parallel=1

after a change in one or many of the projects

subsequent runs come back fine

downgrading to 15.0.3 does not fix it for me, it just hides the error behind [object Object] as per #9342

@miguelmoreba
Copy link

miguelmoreba commented Feb 6, 2023

I tried the proposed solution (manually substituting the code in node_modules and it seems to kick the error further along:

[shared-ui] 🆕 Calculated new version "0.1.0". [shared-ui] 📜 Generated CHANGELOG.md. [shared-ui] 📝 Updated package.json version. [shared-ui] 📦 Committed "chore(shared-ui): release version 0.1.0". [shared-ui] 🔖 Tagged "shared-ui-0.1.0". [shared-ui] ❌ [object Object]

@XIshArkIX
Copy link

XIshArkIX commented Feb 15, 2023

Saw same issue, but in pre-commit husky hook.

I researched how nx lint (nx run <project>:lint) works and here some notes:

  • Looks like husky uses own shell, so in my case i have cwd = C:\Users\roman\Documents\test-project in Powershell and cwd = c:\Users\roman\Documents\test-project in husky shell.
  • It leads to buggy code at node_modules/nx/src/command-line/run-one.js in function calculateDefaultProjectName, so relativeCwd contains only one element.

Here my workaround:

  • Open .husky/pre-commit file inside your project
  • Before yarn lint add export NX_WORKSPACE_ROOT_PATH=$(node -p 'process.cwd()')

@github-actions
Copy link

github-actions bot commented Mar 2, 2023

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! 🙏

@github-actions github-actions bot added the stale label Mar 2, 2023
@FrozenPandaz
Copy link
Collaborator

Closed with #15432

@github-actions
Copy link

github-actions bot commented Apr 3, 2023

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 Apr 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants