Search code examples
typescriptcypressdotenv

Property 'env' does not exist on type 'CypressNpmApi'


I am getting this typescript error when trying to use cypress.env.json file.

cypress.env.json

{
  "email": "[email protected]",
  "password": "Password123"
}

steps.ts

/// <reference types="cypress" />

import Cypress from 'cypress';

Given(/I login to TMDB/, url => {
  Cypress.env('email'); // <- error here
});

Property 'env' does not exist on type 'CypressNpmApi'

https://github.com/inspiraller/next-cypress-cucumber-boilerplate


Solution

  • Credits to - https://github.com/TheBrainFamily/cypress-cucumber-preprocessor/issues/565#event-4746536875

    Was resolved by simply removing my import of Cypress. Since this should be automatically avaiable via typescript in tsconfig.json

    Updated code

    /// <reference types="cypress" />
    
    // import Cypress from 'cypress'; <- remove this line
    
    Given(/I login to TMDB/, url => {
      Cypress.env('email'); // <- Now correctly works
    });