Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

590
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda