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

949
Vistas
Nestjs readFileSync return Cannot read property 'readFileSync' of undefined

I trying get file using method readFileSync:

import fs from 'fs';
import path from 'path';

const templateFile = fs.readFileSync(
    path.resolve(
    __dirname,
    '../mail/templates/exampleTemplate.html',
    ),
    'utf-8',
);

Nest still return me error:

TypeError: Cannot read property 'readFileSync' of undefined

I tryied used to path: ./templates/exampleTemplate.html, but result is the same

I have a structure file:

enter image description here

over 4 years ago · Santiago Trujillo
3 Respuestas
Responde la pregunta

0

Since you're using Typescript and fs does not have a default export, you have to use import * as fs from 'fs'.

over 4 years ago · Santiago Trujillo Denunciar

0

Try

import {readFileSync} from 'fs'
over 4 years ago · Santiago Trujillo Denunciar

0

I fix it by change:

import fs from 'fs';
import path from 'path';

to:

import fs = require('fs');
import path = require('path');
over 4 years ago · Santiago Trujillo 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