Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

578
Views
How to use 'fs' module in React project correctly now (both JavaScript and TypeScript Version)?

I have used import * as fs from 'fs';, import fs from 'fs';, import { readFile } from 'fs';, const fs = require('fs'); & const fs = (window).require('fs');, but none of them runs correctly.

The application created by create-react-app, one is JavaScript Version another one is TypeScript Version. I want know how to solve this issue, and the reason of its cause.

  1. When using import * as fs from 'fs'; & import fs from 'fs', it shows TypeError: fs.readFile is not a function.

  2. When using import { readFile } from 'fs';, it shows Uncaught TypeError: Object(...) is not a function.

  3. When using const fs = (window).require('fs');, it shows window.require is not a function.

  4. When using const fs = require('fs');, it shows fs__WEBPACK_IMPORTED_MODULE_1__.readFile is not a function.

Whether is the matter of config file of project or tsconfig? Thanks for your help.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

fs is a node server side module, and normally browser javascript cannot access the file system. But you could try and set up a backend server using ExpressJS to handle requests and then use fs on your node server to handle file system functions.

Read more about it in :

  • Github create-react-app Issues
  • stackoverflow manipulating files via browser
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!