Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

582
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda