cypress: react-app presets in babel configuration throw error because missing `NODE_ENV` or `BABEL_ENV` environment variables
Current behavior:
All tests fail after updating to 4.2.0
Desired behavior:
Tests should run as they did on 4.1.0
Error message
Oops...we found an error preparing this test file:
/home/travis/build/$PROJECT/cypress/integration/$FILE.spec.js
The error was:
Error: [BABEL] /home/travis/build/$PROJECT/cypress/integration/$FILE.spec.js: Using `babel-preset-react-app` requires that you specify `NODE_ENV` or `BABEL_ENV` environment variables. Valid values are "development", "test", and "production". Instead, received: undefined. (While processing: "/home/travis/build/$PROJECT/node_modules/babel-preset-react-app/index.js") while parsing file: /home/travis/build/$PROJECT/cypress/integration/$FILE.spec.js
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.
Versions
Cypress 4.2.0 Browser: Chrome Application: CRA Environment: Travis and Ubuntu 18.04
Additional information
The issue resolves if pinning version to v4.1.0, but re-appears updating to latest (4.2.0).
Dependencies:
"react": "16.13.0",
"react-dom": "16.13.0",
"react-scripts": "3.4.0",
"@babel/core": "7.8.7",
"@babel/preset-typescript": "7.8.3",
"eslint-plugin-react": "7.19.0",
"eslint-config-react-app": "5.2.0",
"eslint-plugin-cypress": "2.10.3",
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 10
- Comments: 25 (5 by maintainers)
This issue occurs for me in
5.0
, switching to4.10
fixes it.I am just starting out with the tutorial and it is failing in the same place. We also have a .babelrc in the project. Updating babel-core didn’t help the situation. I agree that having addition .env files would be suboptimal and was able to use cross-env to get the tests running.
"cypress-test": "cross-env NODE_ENV=test cypress open",
@iam-frankqiu i just reset babel in my cypress dir something like this should work
.babelrc
Hi @jennifer-shehane , I get this error also with Cypress v5 but works fine in v4.
I determined it occurs if a
.babelrc
file is present in the project root.I’ve pushed a reproducible example here https://github.com/claytonfbell/cypress-issue.
Same here, get it with 5.3.0, when I remove the babel configuration from package.json the error disappear
Solved after I upgrade my babel core
if you
export NODE_ENV=development
it in your shell it work for me with 5.3.0 (an a MackBook machine, but not on a Window machine)I also am facing similar issue, I am using cypress 5.3.0 version
sure mine is also a react project but i have all my cypress scripts in a crypress dir so i have
so i have two files
in the root it looks just like a normal react config file
This issue occurred for my colleague on Window machine, but not on my MacBook (OSX), was fixed also after I removed:
of a create-react-app project with
react-script 3.4.3
andcypress 5.3.0
I have this issue also when changing the version from 4.x to 5.3.0
I also have cypress.env.json defined with project-specific env variables.
We try to keep all versions up-to-date in a regular basis with pinned versions. Since the way to face the error is updating to
4.2.0
and going back to4.1.0
solves it, I would say that a change in cypress is the root cause for it.It both happens locally and on travis (where node_modules are re-created on build) so I guess it shouldn’t make a change.
I found how to “solve” it in
4.2.0
, still it does not explain why it did work fine on previous cypress versions and now it breaks. The difference is onbabel.config.js
andCYPRESS_E2E
is an environment variable we set to determine if we are under a cypress run.Fails:
Passes: