question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to resolve the fs promise (node events)

See original GitHub issue

Current behavior

I have upgraded Cypress to version 10.4 and cucumber-cypress-preprocessor to version 11.4.0. As this needed a bundler, I installed the ESbuild dependencies based on the examples given in the project.

Since then, I am receiving error when trying to run any test in the suite. I tried using fs-extra dependency with no luck I also tried replacing fs.readFileSync(file) with fs.promised.readfile using async and wait with no success.

I found a potential fix but not sure how to add it to my project: https://esbuild.github.io/getting-started/#bundling-for-node

Error: Build failed with 1 error: cypress/support/commands/readXlsx.js:2:23: ERROR: Could not resolve “fs” at failureErrorWithLog (/Users/abc/Test Automation Projects/functional-prj/node_modules/esbuild/lib/main.js:1624:15)

Desired behavior

I want the fs promise to work as before. though I had to add a bundler(Esbuild) for preprocessor 11.4 to work, I am still using node as the package manager.

Test code to reproduce

Cypress.Commands.add(“readXlsx”, (file, sheet) => { const fs = require(“fs”); const XLSX = require(“xlsx”);

const read = ({ file, sheet }) => {
    const buf = fs.readFileSync(file);
    const workbook = XLSX.read(buf, { type: "buffer" });
    const rows = XLSX.utils.sheet_to_json(workbook.Sheets[sheet]);

    return rows;
};

module.exports = {
    read,
};

});

Versions

  • Cypress version: 10.4.0
  • Preprocessor version:11.4.0
  • Node version:16.14.2

Checklist

  • [ x] I’ve read the FAQ.
  • [ x] I’ve read Instructions for logging issues.
  • [x ] I’m not using cypress-cucumber-preprocessor@4.3.1 (package name has changed and it is no longer the most recent version, see #689).

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
badeballcommented, Aug 16, 2022

I can’t really see how this ever worked, in any version.

0reactions
badeballcommented, Aug 31, 2022

You could possibly add it to cypress.config.js setup node events as a task.

I can chime in and say that this is the only way. At no point has anyone been able to do anything else. You simply can’t run a node module in the browser. You might have been able to make a node module compile with earlier versions of browserify / webpack, but it just wouldn’t behave as you’d expect.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Module not found: Can't resolve 'fs' in Next.js application
I deleted node_modules and package-lock. json and then npm cache clean and npm install...but still the same error appears.
Read more >
Module not found: Can't resolve 'fs' · Issue #7755 · vercel/next.js
Bug report Describe the bug I'm using the popular find-up npm package, which has locate-path as a dependency. locate-path requires fs within ...
Read more >
[Node] Simple Next.js app, can't resolve 'fs' - Agents
I'm just trying to get started here with a barebones nextjs app. The app itself runs fine locally, but then I try to...
Read more >
Error handling in Node.js - LogRocket Blog
Deliver reliable software by learning how to handle errors in Node.js using callbacks, promises, and event emitters.
Read more >
Deprecated APIs | Node.js v19.3.0 Documentation
Recover from failed I/O actions explicitly via error event handlers set on the domain instead. DEP0013: fs asynchronous function without callback#. History ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found