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

950
Views
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 answers
Answer question

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 Report

0

Try

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

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 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!