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

setup-ct failing with Angular 13 and Nx v13 #148

Open
chrisstoy opened this issue Dec 21, 2021 · 9 comments
Open

setup-ct failing with Angular 13 and Nx v13 #148

chrisstoy opened this issue Dec 21, 2021 · 9 comments
Labels
bug Something isn't working cypress-angular

Comments

@chrisstoy
Copy link

I'm trying to configure cypress-angular but am running into this issue:
Cannot set property 'demo' of undefined

  1. create a new nx workspace named demo-app and an Angular app named demo
~/dev/temp % npx create-nx-workspace@latest
✔ Workspace name (e.g., org name)     · demo-app
✔ What to create in the new workspace · angular
✔ Application name                    · demo
✔ Default stylesheet format           · scss
✔ Use Nx Cloud? (It's free and doesn't require registration.) · No
  1. follow setup instructions for nx from here: https://github.com/jscutlery/devkit/tree/main/packages/cypress-angular#-setup
~/dev/temp/demo-app(main|✔) % npm i -D @jscutlery/cypress-angular
~/dev/temp/demo-app(main|✚2) % nx g @jscutlery/cypress-angular:setup-ct --project demo
Cannot set property 'demo' of undefined

Running with --verbose I get the following stack trace:

TypeError: Cannot set property 'demo' of undefined
    at addProjectToNxJson (/Users/chris.stoy/dev/temp/demo-app/node_modules/@jscutlery/cypress-angular/node_modules/@nrwl/devkit/src/generators/project-configuration.js:260:42)
    at setProjectConfiguration (/Users/chris.stoy/dev/temp/demo-app/node_modules/@jscutlery/cypress-angular/node_modules/@nrwl/devkit/src/generators/project-configuration.js:216:9)
    at updateProjectConfiguration (/Users/chris.stoy/dev/temp/demo-app/node_modules/@jscutlery/cypress-angular/node_modules/@nrwl/devkit/src/generators/project-configuration.js:36:5)
    at _updateWorkspaceDefinition (/Users/chris.stoy/dev/temp/demo-app/node_modules/@jscutlery/cypress-angular/src/generators/setup-ct/setup-ct.js:104:45)
    at /Users/chris.stoy/dev/temp/demo-app/node_modules/@jscutlery/cypress-angular/src/generators/setup-ct/setup-ct.js:21:9
    at Generator.next (<anonymous>)
    at /Users/chris.stoy/dev/temp/demo-app/node_modules/tslib/tslib.js:117:75
    at new Promise (<anonymous>)
    at __awaiter (/Users/chris.stoy/dev/temp/demo-app/node_modules/tslib/tslib.js:113:16)
    at setupCtGenerator (/Users/chris.stoy/dev/temp/demo-app/node_modules/@jscutlery/cypress-angular/src/generators/setup-ct/setup-ct.js:8:34)

It appears that this is failing because it is trying to read nx.json to modify the projects, but projects are not defined there in Nx v13. Trying to manually add projects to nx.json yields:

 ERROR  As of Nx 13, project configuration should be moved from nx.json to workspace.json/project.json. Please run "nx format" to fix this.

What is interesting is that, if I create an empty workspace first, and THEN add the angular application, this process seems to work.

@dgrbrady
Copy link

dgrbrady commented Feb 9, 2022

Is there a workaround at this time? I have an Angular 13 app in Nx 13 monorepo and even running the default Angular CLI generator fails with the same issue (ng g @jscutlery/cypress-angular:setup-ct --project <app name> vs nx g @jscutlery/cypress-angular:setup-ct --project <app name>)

@edbzn edbzn added bug Something isn't working cypress-angular labels Feb 9, 2022
@edbzn
Copy link
Member

edbzn commented Feb 9, 2022

I would need to investigate the installation generator, but the repo itself is using Angular 13 and Nx 13 so you can configure it by hand as a workaround.

@dgrbrady
Copy link

Thanks for looking into this! If you have the time, could you explain a bit more what you meant by "configure it by hand"? What would need to be configured as a workaround? I could even go off of a general starting point if I knew where to look.

@maxfriedmann
Copy link

maxfriedmann commented Apr 4, 2022

I guess the issue is related to the NX 13 migration of "moving the projects array from nx.json to workspace.json".

@ maintainers: You probably want to update your @nrwl/devkit dependency so that it will detect if users already did that migration or not.

Workaround working for me:

  • open your package.lock file
  • search for node_modules/@jscutlery/cypress-angular
  • change the dependency version of @nrwl/devkit to e.g. 13.7.3
  • remove the entry for "node_modules/@jscutlery/cypress-angular/node_modules/@nrwl/devkit" completely
  • npm i again

@edbzn
Copy link
Member

edbzn commented Apr 4, 2022

The dependency@nrwl/devkit is up to date. I don't reproduce this. Can you confirm it does not occur with the last version?

@maxfriedmann
Copy link

maxfriedmann commented Apr 4, 2022

@edbzn I was talking about this one: https://github.com/jscutlery/devkit/blob/main/packages/cypress-angular/package.json, I can confirm that the setup-ct step works. I did not get it to run yet though.

@yjaaidi
Copy link
Member

yjaaidi commented May 12, 2022

Hi @maxfriedmannm, sorry for responding so late.
So setu-ct works? What kind of trouble are you getting afterwards?

@Cabinet20
Copy link

Cabinet20 commented Aug 12, 2022

I have a project on Nx and Angular on v14 and I get the same error. Our mono-repo uses angular.json as the root project file. I manually edited the references in your node_modules folder to change nx.json to angular.json and it "worked" feels hacky though and not sure it won't cause issues down the road.

Any way support can be added for Nx monorepos not using the nx.json file?

@Cabinet20
Copy link

I would need to investigate the installation generator, but the repo itself is using Angular 13 and Nx 13 so you can configure it by hand as a workaround.

Is there a guide to manually configuring this? Is it similar to the way it was done on the old GitHub?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cypress-angular
Projects
None yet
Development

No branches or pull requests

6 participants