24

Trying to execute any of the tests leads to this error popping up.

I am using Cypress 6.5.0

Really clueless about what to do.

Sorry for the image, but it was much better to show it this way.

enter image description here

And also the StackTrace.

at Object../node_modules/is-ci/node_modules/ci-info/index.js (webpack:///node_modules/is-ci/node_modules/ci-info/index.js:5:1)
at __webpack_require__ (webpack:///webpack/bootstrap:19:1)
at Object../node_modules/is-ci/index.js (webpack:///node_modules/is-ci/index.js:3:18)
at __webpack_require__ (webpack:///webpack/bootstrap:19:1)
at Object.eval (webpack:///node_modules/cypress/lib/util.js:21:14)
at Object../node_modules/cypress/lib/util.js (http://localhost:37869/__cypress/tests?p=test/e2e/support/index.js:87250:31)
at __webpack_require__ (webpack:///webpack/bootstrap:19:1)
at Object.eval (webpack:///node_modules/cypress/index.js:9:14)
at Object../node_modules/cypress/index.js (http://localhost:37869/__cypress/tests?p=test/e2e/support/index.js:82972:31)
at __webpack_require__ (webpack:///webpack/bootstrap:19:1)
From previous event:
at runScriptsFromUrls (http://localhost:37869/__cypress/runner/cypress_runner.js:177985:98)
at Object.runScripts (http://localhost:37869/__cypress/runner/cypress_runner.js:177999:11)
at $Cypress.onSpecWindow (http://localhost:37869/__cypress/runner/cypress_runner.js:167733:19)
lastSheep
  • 397
  • 1
  • 5
  • 13
  • May happen when using Next since process.env doesn't get inlined from the build, this is some Next.js magic. I am still looking for a way to mock this "process" object, setting window.process in the before hook doesn't work because the build fails. – Eric Burel May 17 '22 at 12:21

7 Answers7

44

This happened for me when I imported cypress within my test, removing that fixed the issue

  • 1
    I confirm that importing cypress in the test file causes the error, for me, it was eslint complaining for undefined `describe`, `it` and `cy`, which I fixed by adding `import { cy, describe, it } from "cypress";`, but this line is causing the error. Anyway, to supress eslint errors for cypress, follow these instructions https://stackoverflow.com/a/66268013/477932 – ubugnu Jul 06 '23 at 09:54
5

Sometimes by mistake, Visual Studio Code will auto-import unnecessary libraries. You should delete them. For me it was

import { cli } from 'cypress';

canbax
  • 3,432
  • 1
  • 27
  • 44
1

It looks like you have something in /support/index.js (since it's mentioned in the stack trace) that should be in /plugins/index.js (since it has an invalid use of process which is only available in node.js).

Cypress runs both a browser process and a background node.js process.

/support/index.js is used to augment the browser process, and /plugins/index.js is used to augment the node.js process.

If you mix them up when adding a library, a task, or a file preprocessor you get an error of the type you show.

What's in /support/index.js?

1

Remove import cypress from "cypress" from your POM fi

1

If you just updated to react-scripts 5.x and facing this issue, there is currently a PR to fix it but a workaround to get your tests working ASAP is to update the env.js file in the react scripts node module as referenced in this PR.

NB: If you have a private artifact repository manager on jfrog it is advisable to push this fix to your registry and pull react scripts from there until the fix becomes publicly available.

TLDR; You just updated to react 5.x and your cypress tests show the error below;

Cypress process is not defined error

Solution File: node_modules/react-scripts/config/env.js

Change the stringified method to:

    // Stringify all values so we can feed into webpack DefinePlugin
    const stringified = {
    'process':{}, // This is the only line added to the previous method
    'process.env': Object.keys(raw).reduce((env, key) => {
      env[key] = JSON.stringify(raw[key]);
      return env;
    }, {}),
    };
draysams
  • 1,199
  • 1
  • 11
  • 18
0

When we drive out gloval variable from JSON visual studiao automatically Import import { cli } from 'cypress';

  • This is offering the [same advice as @canbax offered last year](https://stackoverflow.com/a/67871562/3025856)—though the confusing wording makes it hard to be sure that's what you're saying. – Jeremy Caney Feb 01 '22 at 00:44
0

I commented following line from support/command.js and that reso I am using cypress 8.7

const { defineConfig } = require('cypress')

Randi
  • 61
  • 7