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

237
Vistas
TypeError: fs.readdirSync is not a function when using Winston logger in React

I am developing an application in React (using JavaScript) and I want to create a log file using the package Winston-react. I have followed their tutorial from here: https://github.com/afex-connect/winston-react#readme (obviously adapted to javascript)

Install

npm install winston-react

Usage App.js:

import React from 'react';
import winston from 'winston';
import { WinstonProvider } from 'winston-react';

const logger = winston.createLogger({
  // ...
  transports: [
    // ...
    new winston.transports.Console()
  ]
});

const App = () => (
  <WinstonProvider logger={logger}>
    <div>
      your awesome application
    </div>
  </WinstonProvider>
);

Using hooks:

import React from 'react';
import { useWinstonLogger } from 'winston-logger';

const Component = () => {
  const logger = useWinstonLogger();

  React.useEffect(() => {
    logger.info('your awesome information log!');
  });

  return (
    <div>
      your awesome component
    </div>
  );
};

But it is throwing this error: TypeError: fs.readdirSync is not a function

node_modules/pkginfo/lib/pkginfo.js:95
  92 |   dir = path.dirname(pmodule.filename);
  93 | }
  94 | 
> 95 | var files = fs.readdirSync(dir);
     | ^  96 | 
  97 | if (~files.indexOf('package.json')) {
  98 |   return path.join(dir, 'package.json');
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Are you running your application in node or in a browser? The fs module does not exist in the browser.

Also, if you want to create a log file then you need to use the File transport. Your code sample only shows the Console transport, which will write to the console.

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