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?

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

  1. 9711 705746There a couple of interesting points more than time here but I dont know if I see them all center to heart. There exists some validity but Let me take hold opinion until I look into it further. Really excellent post , thanks and now we want more! Included with FeedBurner at exactly the same time 597926


Leave a Comment