cypress
cypress copied to clipboard
Adding @cypress/schematic to Angular 17 default gives: Could not find NgModule
Current behavior
As of Angular 17 it doesn't make use of modules anymore by default. But after running ng generate component I get the following error:
Could not find an NgModule. Use the '--skip-import' option to skip importing in NgModule.
--skip-import does work, but doesn't create a standalone component. (So you miss the standalone & imports properties)
I added "@cypress/schematic" by using ng add "@cypress/schematic"
Desired behavior
--skip-import should be the default.
Test code to reproduce
install angular 17
ng add @cypress/schematic
ng g c test123
Cypress Version
13.6.0
Node version
18.14.2
Operating System
Windows 10 pro 19045.3693
Debug Logs
No response
Other
No response
This issue has not had any activity in 180 days. Cypress evolves quickly and the reported behavior should be tested on the latest version of Cypress to verify the behavior is still occurring. It will be closed in 14 days if no updates are provided.
This issue has been closed due to inactivity.
I just ran into the same problem with a new project. Shouldn't it be fixed, so cypress works with angular's standalone components? After all, they are the new default.
The issue exists after migrating from modules to standalone components. As it looks like it is not anymore possible to generate a component with "ng generate component test". Even with an explicit standalone configuration on project and root level in the angular.json the error still occurs.
Here are the steps to reproduce the error:
- npm install -g @angular/cli@17 (You can also try it on Angular 18, dont know if it occurs also there, but the propability is high)
- ng new standalone-project --standalone
- ng add @cypress/schematic --e2e --component
- ng g c test
Workaround:
Generate your component with the standalone option:
- ng g c
--standalone
Very annoying that this schematic overwrites the default angular ones.
@jennifer-shehane can someone please look into this issue? I never would have expected Cypress to completely replace all of my tests in my component schematic. That and not actually updating to follow the current defaults of the extended schematic.
To fix this issue, you need to change a configuration in the angular.json file.
Simply change the order in the cli.schematicCollections so that @schematics/angular is in the first position, as shown in the example below:
"cli": { "analytics": false, "schematicCollections": [ "@schematics/angular", "@cypress/schematic" ] }
Related to https://github.com/cypress-io/cypress/issues/26738 and https://github.com/angular/angular-cli/issues/25186.
To fix this issue, you need to change a configuration in the angular.json file.
Simply change the order in the cli.schematicCollections so that @schematics/angular is in the first position, as shown in the example below:
"cli": { "analytics": false, "schematicCollections": [ "@schematics/angular", "@cypress/schematic" ] }
When I do this there are no cypress specs generated alongside my components. How can I fix this?