I recently upgraded cypress from 9 to 11 and when I start it using
npx cypress open
I do not get any issues running the tests.
When I start it using:
npx cypress run
It returns me the following error:
✘ [ERROR] Could not resolve "node:perf_hooks"
node_modules/@cucumber/cucumber/lib/time.js:27:34:
27 │ const node_perf_hooks_1 = require("node:perf_hooks");
╵ ~~~~~~~~~~~~~~~~~
The package "node:perf_hooks" wasn't found on the file system but is built into node. Are you trying to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.
Error: Build failed with 1 error:
node_modules/@cucumber/cucumber/lib/time.js:27:34: ERROR: Could not resolve "node:perf_hooks"
at failureErrorWithLog (/node_modules/esbuild/lib/main.js:1636:15)
at /node_modules/esbuild/lib/main.js:1048:25
at runOnEndCallbacks (/node_modules/esbuild/lib/main.js:1471:45)
at buildResponseToResult (/node_modules/esbuild/lib/main.js:1046:7)
at /node_modules/esbuild/lib/main.js:1075:16
at responseCallbacks.<computed> (/node_modules/esbuild/lib/main.js:697:9)
at handleIncomingPacket (/node_modules/esbuild/lib/main.js:752:9)
at Socket.readFromStdout (/node_modules/esbuild/lib/main.js:673:7)
at Socket.emit (node:events:518:28)
at Socket.emit (node:domain:488:12)
at addChunk (node:internal/streams/readable:559:12)
at readableAddChunkPushByteMode (node:internal/streams/readable:510:3)
at Socket.Readable.push (node:internal/streams/readable:390:5)
at Pipe.onStreamRead (node:internal/stream_base_commons:190:23)
I am afraid that I am missing some polyfill plugins, my current ones are:
const createEsbuildPlugin = require('@badeball/cypress-cucumber-preprocessor/esbuild');
const { NodeModulesPolyfillPlugin } = require('@esbuild-plugins/node-modules-polyfill');
const nodePolyfills = require('@esbuild-plugins/node-modules-polyfill').NodeModulesPolyfillPlugin;
...
on(
'file:preprocessor',
createBundler({
plugins: [NodeModulesPolyfillPlugin(), nodePolyfills(), createEsbuildPlugin.default(config)],
}),
);
Finally, I solved removing the import of cypress.config.ts in one of my step definition files. I was doing something like:
import base from '../../../../cypress.config'; // WRONG
which is absolutely wrong, this fixed for me all the errors like:
[ERROR] Could not resolve "fs"
[ERROR] Could not resolve "fs/promises"
[ERROR] Could not resolve "stream"
[ERROR] Could not resolve "stream/promises"
[ERROR] Could not resolve "console"
[ERROR] Could not resolve "crypto"
...
etc.
I get the hints reading this answer.