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

971
Views
ReferenceError: TextEncoder is not defined with mongodb nodes

I am trying to run jest test cases but I am facing error -

ReferenceError: TextEncoder is not defined .

Node version -14.18.0.

Mongodb NPM - 4.1.3 .

Typescript version - 4.4.3.

Below is my test code --

beforeAll(() => {
  connection = new Connection();
});

Below is my connection class code

import { MongoClient, Db, MongoClientOptions } from 'mongodb';

class MongoConnection {
  
public async conn(){
    await MongoClient.connect('', options);
}
}

Error --

FAIL connection.test.ts

● Test suite failed to run

ReferenceError: TextEncoder is not defined

  
> 1 | import { MongoClient, Db, MongoClientOptions } from 'mongodb';
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Ok the problem got solved.

I have added at the top --

global.TextEncoder = require("util").TextEncoder;
global.TextDecoder = require("util").TextDecoder;

Not sure why the error was showing.

about 4 years ago · Juan Pablo Isaza 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!