How to remove "_fs.readFileSync is not a function" error from cypress test

I want to read data from a particular cell of my excel sheet and then use that data in my cypress tests. The file name is ‘qaautomation.xlsx’ and sheet name is ‘Input’ and I want to read data from cell B2. I have written the following code to access the value

 /// <reference types ="cypress" />
var xlsx = require ("xlsx");
var workbook= xlsx.readFile("qaautomation.xlsx");
var worksheet= workbook.Sheets["Input"];
var cellB2value= 'B2';
var cellB2=worksheet[cellB2value];
var cellB2_value=(cellB2.v);

Code written below is where the value would be used.

        describe('Typing the address', function(){
    
    it ('should open the link', function(){
        cy.visit(cellB2_value) //here comes the value from cell B2
})})

When I run the above code I get the following error

The following error originated from your test code, not from Cypress.

  > _fs.readFileSync is not a function

When Cypress detects uncaught errors originating from your test code it will automatically fail the current test.

Cypress could not associate this error to any specific test.

We dynamically generated a new test to display this failure.

Check your console for the stack trace or click this message to see where it originated from.

Is there any way to remove this error?

6 thoughts on “How to remove "_fs.readFileSync is not a function" error from cypress test”

Leave a Comment