https://cypress.io logo
Environment variable CYPRESS_RECORD_KEY does not l...
# i-need-help
b
I am trying to set CYPRESS_RECORD_KEY through a .env file, My project structure looks like this:
Copy code
root/
  .env
  .git
  frontend/
    src/
    cypress/
    .env -> The CYPRESS_RECORD_KEY variable is located here
    cypress.config.ts
    package.json
  backend/
    ...
In the cypress.config.ts I added this to load the correct .env:
Copy code
dotenv.config({ path: `.env` });
dotenv.config();
And now when I run cypress using
npm run cypress-test
which runs
cypress run --record
I get the error
You passed the --record flag but did not provide us your Record Key.
Can I get any help? - I tried adding the dotenv setup into
plugins/index.ts
- I tried adding the variables to cypress.env.json in the frontend folder. The only thing that seems to work is passing the env variables in the run command it self.
UPDATE: When I added a console log below the dotenv setup like this:
Copy code
let res = dotenv.config({ path: `.env`});
console.log(res.parsed);
I got the correct output, meaning dotenv was successfully loading the env variables:
Copy code
{
  REACT_APP_STAGE: 'compose',
  REACT_APP_DASHBOARD_VERSION: 'local',
  REACT_APP_MOBILE_REDIRECT: 'false',
  DISABLE_ESLINT_PLUGIN: 'true',
  SKIP_PREFLIGHT_CHECK: 'true',
  CYPRESS_RECORD_KEY: 'xxxxx',
  CYPRESS_API_URL: 'https://cy.currents.dev',
  CYPRESS_BASE_URL: 'https://xxxxxx.com/'
}
6 Views