cypress icon indicating copy to clipboard operation
cypress copied to clipboard

Adding @cypress/schematic to Angular 17 default gives: Could not find NgModule

Open ray1618 opened this issue 1 year ago • 9 comments

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

ray1618 avatar Dec 06 '23 11:12 ray1618

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.

cypress-app-bot avatar Jun 04 '24 01:06 cypress-app-bot

This issue has been closed due to inactivity.

cypress-app-bot avatar Jun 18 '24 01:06 cypress-app-bot

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.

tomnar avatar Jul 15 '24 07:07 tomnar

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:

  1. 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)
  2. ng new standalone-project --standalone
  3. ng add @cypress/schematic --e2e --component
  4. ng g c test

Workaround:

Generate your component with the standalone option:

  1. ng g c --standalone

hennihaus avatar Sep 07 '24 10:09 hennihaus

Very annoying that this schematic overwrites the default angular ones.

rgant avatar Jan 23 '25 23:01 rgant

@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.

rgant avatar Jan 23 '25 23:01 rgant

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" ] }

erickarruzzo avatar Feb 14 '25 00:02 erickarruzzo

Related to https://github.com/cypress-io/cypress/issues/26738 and https://github.com/angular/angular-cli/issues/25186.

helkv avatar May 14 '25 09:05 helkv

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?

hennihaus avatar May 30 '25 14:05 hennihaus