cypress: Importing anything from @angular/cdk breaks E2E test build (Angular 13)
Current behavior
When I try to import anything from @angular/cdk (Angular 13), Cypress fails to build the test.
This used to work in Angular 12, so I am not exactly sure where is the problem.
The error I am getting:
Error: Webpack Compilation Error
./node_modules/@angular/cdk/fesm2015/platform.mjs
Module not found: Error: Can't resolve '@angular/common' in 'C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\fesm2015'
resolve '@angular/common' in 'C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\fesm2015'
Parsed request is a module
using description file: C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\package.json (relative path: ./fesm2015)
Field 'browser' doesn't contain a valid alias configuration
resolve as module
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\fesm2015\node_modules doesn't exist or is not a directory
C:\dev\workspace\exp\cypress-test\node_modules\@angular\node_modules doesn't exist or is not a directory
C:\dev\workspace\exp\cypress-test\node_modules\node_modules doesn't exist or is not a directory
C:\dev\workspace\exp\node_modules doesn't exist or is not a directory
C:\node_modules doesn't exist or is not a directory
looking for modules in C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules
using description file: C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
looking for modules in C:\dev\workspace\exp\cypress-test\node_modules
using description file: C:\dev\workspace\exp\cypress-test\package.json (relative path: ./node_modules)
Field 'browser' doesn't contain a valid alias configuration
using description file: C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\package.json (relative path: .)
no extension
Field 'browser' doesn't contain a valid alias configuration
looking for modules in C:\dev\node_modules
No description file found
Field 'browser' doesn't contain a valid alias configuration
looking for modules in C:\dev\workspace\node_modules
No description file found
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common is not a file
.js
Field 'browser' doesn't contain a valid alias configuration
using description file: C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\package.json (relative path: ./node_modules/@angular/common)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
No description file found
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.json doesn't exist
.jsx
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
No description file found
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\dev\node_modules\@angular\common doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.jsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.json doesn't exist
.jsx
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\node_modules\@angular\common doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\dev\node_modules\@angular\common.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.mjs doesn't exist
.coffee
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.jsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\node_modules\@angular\common.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
C:\dev\node_modules\@angular\common.json doesn't exist
.jsx
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.coffee doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.mjs doesn't exist
.coffee
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\node_modules\@angular\common.json doesn't exist
.jsx
Field 'browser' doesn't contain a valid alias configuration
C:\dev\node_modules\@angular\common.jsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.coffee doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\node_modules\@angular\common.jsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
C:\dev\node_modules\@angular\common.mjs doesn't exist
.coffee
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.tsx doesn't exist
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\node_modules\@angular\common.mjs doesn't exist
.coffee
Field 'browser' doesn't contain a valid alias configuration
C:\dev\node_modules\@angular\common.coffee doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.tsx doesn't exist
as directory
existing directory
using path: C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index
using description file: C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\package.json (relative path: ./index)
no extension
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\node_modules\@angular\common.coffee doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\dev\node_modules\@angular\common.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
as directory
C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common doesn't exist
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index doesn't exist
.js
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\node_modules\@angular\common.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
C:\dev\node_modules\@angular\common.tsx doesn't exist
as directory
C:\dev\node_modules\@angular\common doesn't exist
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.js doesn't exist
.json
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\node_modules\@angular\common.tsx doesn't exist
as directory
C:\dev\workspace\node_modules\@angular\common doesn't exist
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.json doesn't exist
.jsx
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.jsx doesn't exist
.mjs
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.mjs doesn't exist
.coffee
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.coffee doesn't exist
.ts
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.ts doesn't exist
.tsx
Field 'browser' doesn't contain a valid alias configuration
C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.tsx doesn't exist
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\fesm2015\node_modules]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\node_modules]
[C:\dev\workspace\exp\cypress-test\node_modules\node_modules]
[C:\dev\workspace\exp\node_modules]
[C:\node_modules]
[C:\dev\node_modules\package.json]
[C:\dev\workspace\node_modules\package.json]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.js]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common]
[C:\dev\node_modules\@angular\common\package.json]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.json]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.js]
[C:\dev\workspace\node_modules\@angular\common\package.json]
[C:\dev\node_modules\@angular\common]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.jsx]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.json]
[C:\dev\workspace\node_modules\@angular\common]
[C:\dev\node_modules\@angular\common.js]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.mjs]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.jsx]
[C:\dev\workspace\node_modules\@angular\common.js]
[C:\dev\node_modules\@angular\common.json]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.coffee]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.mjs]
[C:\dev\workspace\node_modules\@angular\common.json]
[C:\dev\node_modules\@angular\common.jsx]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.ts]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.coffee]
[C:\dev\workspace\node_modules\@angular\common.jsx]
[C:\dev\node_modules\@angular\common.mjs]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common.tsx]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.ts]
[C:\dev\workspace\node_modules\@angular\common.mjs]
[C:\dev\node_modules\@angular\common.coffee]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\cdk\node_modules\@angular\common.tsx]
[C:\dev\workspace\node_modules\@angular\common.coffee]
[C:\dev\node_modules\@angular\common.ts]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index]
[C:\dev\workspace\node_modules\@angular\common.ts]
[C:\dev\node_modules\@angular\common.tsx]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.js]
[C:\dev\workspace\node_modules\@angular\common.tsx]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.json]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.jsx]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.mjs]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.coffee]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.ts]
[C:\dev\workspace\exp\cypress-test\node_modules\@angular\common\index.tsx]
@ ./node_modules/@angular/cdk/fesm2015/platform.mjs 3:0-52 38:14-31
@ ./cypress/integration/spec.ts
Desired behavior
I should be able to import from @angular/cdk
Test code to reproduce
import {
getSupportedInputTypes,
} from '@angular/cdk/platform';
describe('My First Test', () => {
// just a test
const types = getSupportedInputTypes();
it('Visits the initial project page', () => {
cy.visit('/')
cy.contains('Welcome')
})
})
Cypress Version
9.1.0
Other
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 31
- Comments: 44 (2 by maintainers)
Commits related to this issue
- test: ✅ fix cypress tests Cf. https://github.com/cypress-io/cypress/issues/19066 & https://github.com/storybookjs/storybook/issues/14012 — committed to marmicode/marmicode by yjaaidi 2 years ago
- fixed a sticky bug where webpack wasn't correctly loading angular libraries like @angular/core - needed in order to correctly mount the referenced angular app - pretty much according to cypress-io/cy... — committed to MattForgione/fullstack-todo by MattForgione 2 years ago
- Running into weird compilation error. See https://github.com/cypress-io/cypress/issues/19066#issuecomment-1144152738 — committed to dockstore/dockstore-ui2 by coverbeck a year ago
- Running into weird compilation error. See https://github.com/cypress-io/cypress/issues/19066#issuecomment-1144152738 — committed to dockstore/dockstore-ui2 by coverbeck a year ago
- Use OpenAPI instead of Swagger in the UI (#1796) #5538 Some followup required due to a blocking issue, see #5550 Ran into a weird compilation error with Cypress, see See https://github.com/c... — committed to dockstore/dockstore-ui2 by coverbeck a year ago
@aleesaan We are also using NX and the workarounds mentioned here didn’t work for us either. However, something that did work was patching the rule that @myflowpl provided into the existing webpack config, rather than writing our own.
(Also check your cypress.json to see where you are meant to be putting the plugin and if you should be using .js or .ts)
Here is our plugin file
I’m seeing the same issue after upgrading to ng 13, except I’m seeing failures loading
@angular/coreand@angular/common. To be clear, I did not require a custom webpack config before upgrading to ng 13, but as of ng 13 an override is required.I’d already worked through a number of related errors (eg jest also broke after the change to the angular library package format to .mjs files). Here’s the fix that worked for me:
Hopefully the default
@cypress/webpack-preprocessorwill be updated soon to handle this scenario, and I can remove this workaround.want to say for @aleesaan and others that are stuck by this. my team was also having trouble getting fully upgraded to Angular 13 because of this but we were able to get the workaround @noggin182 provided to work
what was missing was installing the peer dependencies of
@cypress/webpack-preprocessorwhich are specified here in the second npm install command in the Installation sectionso for completeness sake and for people that like to scroll to the bottom (me) the full workaround that worked in my case with Angular 13 and cypress 9.7.0 is:
install the @cypress/webpack-batteries-included-preprocessor and @cypress/webpack-preprocessor packages:
npm install --save-dev @cypress/webpack-preprocessor @cypress/webpack-batteries-included-preprocessorinstall the peer dependencies of @cypress/webpack-preprocessor:
npm install --save-dev @babel/core @babel/preset-env babel-loader webpackupdate the cypress plugin file to resemble this depending on your existing plugins (credit to @noggin182):
cypress/plugins/index.ts(could alternatively becypress/plugins/index.js)hope that helps people while the devs come up with a long term fix.
In case anyone also using ngrx, in my case I had to modify the regex a bit to
/[/\\](@angular|@ngrx)[/\\].+\.m?js$/@johncrim thanks, your workaround helped me a lot 💪
but after putting your code i got this error:
then I had to add resolve->fullySpecified: false to config lines into your webpack config:
Now it’s working 🤩
I’m using Nx monorepo and .js files as webpack config & plugins file, so here are my files:
apps\web-e2e\src\plugins\index.jsapps\web-e2e\cypress.webpack.config.jsFor anyone using the nrwl cypress 10 upgrade generator , i.e
nx generate @nrwl/cypress:migrate-to-cypress-10we found that the configuration above stopped working.Adding it directly in
cypress.config.tsfixed it for us.We had multiple issues with cypress and webpack 5. Mainly publicPath and the platform-browser errors. Solved using a combination of fixes found in various issues.
Used the below config in plugin.js and pointed all our e2e apps at this shared plugin config. I hope this can help someone else move forward with nx + angular 13 + cypress. Was a complete headache
Hi,
we are already using the workaround, but it seems that test execution time is longer. Will there be an offical fix soon? Thank you in advance
In our case we managed to make the test files compile using the @cypress/webpack-batteries-included-preprocessor and following their example to support typescript as speculated here: https://github.com/cypress-io/cypress/tree/develop/npm/webpack-batteries-included-preprocessor#usage
Not sure why this package can transpile the packages from
@angular/cdkwhile the default config from cypress cannot, since this is supposed to be the actual default cypress is using to transpile test files if you don’t use a custom ‘file:preprocessor’ at allHey @adhed yes, I still have it 😭 We’re completely stuck and can’t upgrade Angular because of this, I wonder who we can poke to look into it and fix it?
After upgrading all dependencies (including Cypress, Nx, and Angular) to latest I still get the following:
After upgrading to Angular 16 (from 14) and Cypress 13.6.0 (from 12.17.1), the issue seems to be resolved. I was able to remove the custom webpack preprocessor and alias handling.
The workaround by johncrim worked perfectly for us. Additionally, since we used alias imports in the Cypress tests itself, we had to add them to the webpack config using the tsconfig-paths-webpack-plugin .
Hey, I just bumped into the same issue as well. Is there any plans to fix the issue? None of the workarounds work for me
Hi, we were also stuggling with this issue after upgrading to angular 13. The posted workarounds are working, but they require some dependencies that I don’t want to deal with when updating my packages. Are there any plans to fix this issue? Thanks
@johncrim - yes, I have
"@angular/compiler-cli": "^13.2.1"in my dev dependencies.I also have the
fullySpecified=false, I get this error trying the same setup @noggin182 suggested. Namely, I installed@cypress/webpack-batteries-included-preprocessoras a dev dependency, and then added this to myplugins/index.jsfile:But I still get the error 😢 Am I missing something else?
@basvandorst I just tried with ^9.4 but still same issue 😦 aka
Error: Cannot find module '@angular/compiler-cli/linker/babel'Any other ideas?
@noggin182 ! You are the best! It works like a dream,
(Pd: Sorry for my late answer to all the people who tagged me 😃 )
@noggin182 thanks a lot, it is much simpler and it’s working for me 💪 and thanks for suggesting now to change plugins/index.js to .ts files, didn’t now that it’s in cypress.json
@distante It’s working now, with the @noggin182 workaround where you extend, not overwrite webpack config, the ts paths aliases are back working, so for me this workaround is fully what we need 🥳
Confirm that @johncrim suggestion works. One thing that you may need to notice is that the version of Webpack should >= 5 in order to support
fullySpecified.