29

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)
1
  • 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. Commented May 17, 2022 at 12:21

8 Answers 8

51

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

Sign up to request clarification or add additional context in comments.

1 Comment

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 stackoverflow.com/a/66268013/477932
6

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

import { cli } from 'cypress';

Comments

2

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?

Comments

1

Remove import cypress from "cypress" from your POM fi

Comments

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;
    }, {}),
    };

Comments

0

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

1 Comment

This is offering the same advice as @canbax offered last year—though the confusing wording makes it hard to be sure that's what you're saying.
0

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

const { defineConfig } = require('cypress')

Comments

0

For me, this issue was coming because of this statement in command.js file.

const cypress = require("cypress");

I removed it and the script worked perfectly.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.