Current behavior
After upgrade to Cypress 12.17.4 which uses Webpack 5, I started getting this error:
Oops...we found an error preparing this test file:
> cypress/support/e2e.ts
The error was:
Error: Webpack Compilation Error
Module not found: Error: Can't resolve 'process/browser' in '/Users/me/Projects/next-multilingual/node_modules/sinon/pkg'
Did you mean 'browser.js'?
BREAKING CHANGE: The request 'process/browser' failed to resolve only because it was resolved as fully specified
(probably because the origin is strict EcmaScript Module, e. g. a module with javascript mimetype, a '*.mjs' file, or a '*.js' file where the package.json contains '"type": "module"').
The extension in the request is mandatory for it to be fully specified.
Add the extension to the request.
Cannot read properties of undefined (reading 'module')
at handle (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/node_modules/@cypress/webpack-preprocessor/dist/index.js:212:23)
at finalCallback (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:441:32)
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:505:17
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/HookWebpackError.js:68:3
at Hook.eval [as callAsync] (eval at create (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:18:14)
at Cache.storeBuildDependencies (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Cache.js:122:37)
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:501:19
at Hook.eval [as callAsync] (eval at create (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:18:14)
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:498:23
at Compiler.emitRecords (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:919:5)
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:490:11
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:885:14
at Hook.eval [as callAsync] (eval at create (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:18:14)
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:882:27
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:2818:7
at done (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/neo-async/async.js:3522:9)
at Hook.eval [as callAsync] (eval at create (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:6:1)
at Hook.CALL_ASYNC_DELEGATE [as _callAsync] (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/tapable/lib/Hook.js:18:14)
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/webpack/lib/Compiler.js:736:33
This occurred while Cypress was compiling and bundling your test code. This is usually caused by:
- A missing file or dependency
- A syntax error in the file or one of its dependencies
Fix the error in your code and re-run your tests.
(Results)
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 0 │
│ Passing: 0 │
│ Failing: 1 │
│ Pending: 0 │
│ Skipped: 0 │
│ Screenshots: 0 │
│ Video: false │
│ Duration: 0 seconds │
│ Spec Ran: anchor-links.cy.ts │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
Desired behavior
Based on the changeslog from 12.17.4, there should not be any impact after upgrading.
I tried to fix the issue myself by installing @cypress/webpack-preprocessor and @babel/preset-typescript but got nowhere.
I also tried to pin @cypress/webpack-batteries-included-preprocessor to v2.x.x and hooking into the file:preprocessor plugin event.
I had to:
- run
npm install @cypress/webpack-batteries-included-preprocessor@^2.0.0 --save-dev
- Add this in my `cypress.config.ts:
import preprocessor from '@cypress/webpack-batteries-included-preprocessor'
import { defineConfig } from 'cypress'
export default defineConfig({
video: false,
screenshotOnRunFailure: false,
e2e: {
setupNodeEvents: (on) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-call
on('file:preprocessor', preprocessor())
},
baseUrl: 'http://localhost:3000',
},
})
Unfortunately as soon as I do this I get new errors:
Oops...we found an error preparing this test file:
> cypress/e2e/anchor-links.cy.ts
The error was:
Error: You are attempting to run a TypeScript file, but do not have TypeScript installed. Ensure you have 'typescript' installed to enable TypeScript support.
The file: /Users/me/Projects/next-multilingual/cypress/e2e/anchor-links.cy.ts
at Object.handler (/Users/me/Projects/next-multilingual/node_modules/@cypress/webpack-batteries-included-preprocessor/index.js:162:29)
at invoke (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:183:18)
at /Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:59:14
at tryCatcher (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/util.js:16:23)
at Function.Promise.attempt.Promise.try (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/bluebird/js/release/method.js:39:29)
at Object.wrapChildPromise (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:58:23)
at Object.wrap (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/preprocessor.js:47:8)
at RunPlugins.execute (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:157:29)
at EventEmitter.<anonymous> (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/child/run_plugins.js:56:12)
at EventEmitter.emit (node:events:513:28)
at EventEmitter.emit (node:domain:489:12)
at process.<anonymous> (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/packages/server/lib/plugins/util.js:33:22)
at process.emit (node:events:513:28)
at process.emit (node:domain:489:12)
at process.emit.sharedData.processEmitHook.installedValue [as emit] (/Users/me/Library/Caches/Cypress/12.17.4/Cypress.app/Contents/Resources/app/node_modules/@cspotcode/source-map-support/source-map-support.js:745:40)
at emit (node:internal/child_process:937:14)
at processTicksAndRejections (node:internal/process/task_queues:83:21)
My only solution is to downgrade Cypress to 12.17.3
Test code to reproduce
- Clone https://github.com/Avansai/next-multilingual
- Upgrade Cypress
- run
npm install
- Run
npm run test
Cypress Version
12.17.4
Node version
v18.16.0
Operating System
macOS 13.4.1
Debug Logs
No response
Other
No response
Current behavior
After upgrade to Cypress
12.17.4which uses Webpack 5, I started getting this error:Desired behavior
Based on the changeslog from
12.17.4, there should not be any impact after upgrading.I tried to fix the issue myself by installing
@cypress/webpack-preprocessorand@babel/preset-typescriptbut got nowhere.I also tried to pin @cypress/webpack-batteries-included-preprocessor to v2.x.x and hooking into the file:preprocessor plugin event.
I had to:
npm install @cypress/webpack-batteries-included-preprocessor@^2.0.0 --save-devUnfortunately as soon as I do this I get new errors:
My only solution is to downgrade Cypress to
12.17.3Test code to reproduce
npm installnpm run testCypress Version
12.17.4
Node version
v18.16.0
Operating System
macOS 13.4.1
Debug Logs
No response
Other
No response