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

422
Views
const utf8Encoder = new TextEncoder(); in Node js

I am trying to use mongodb so I install mongoose package

but the problem is when I am writing like this

const express = require("express");
const dotenv = require("dotenv");
const mongoose = require("mongoose"); //getting error here

It showing me error like this

const utf8Encoder = new TextEncoder();
                    ^

ReferenceError: TextEncoder is not defined

If I am commenting mongoose line I don't get any error but I need to use this even i checked my node version its 16.5.0 I tried looking an old post where same error occur but its not understandable to me any help ? old post link enter link description here

how to fix this error

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Open your encoding.js folder in node_modules>whatwg-url>dist

and write this code

"use strict";
var util= require('util');
const utf8Encoder = new util.TextEncoder();
const utf8Decoder = new util.TextDecoder("utf-8", { ignoreBOM: true });

in place of

"use strict";
const utf8Encoder = new TextEncoder();
const utf8Decoder = new TextDecoder("utf-8", { ignoreBOM: true });

all you where missing is this small part by including utils

var util= require('util');
const utf8Encoder = new util.TextEncoder();
const utf8Decoder = new util.TextEncoder("utf-8", { ignoreBOM: true });
about 4 years ago · Juan Pablo Isaza Report

0

Open your encoding.js folder in node_modules

  1. Open the node_modules
  2. Locate the whawg-url folder and open.
  3. Search for dist folder - there, you'd find the encoding.js folder
  4. Open via VS Code or any IDE of your choice.

Replace these line of code

"use strict";
const utf8Encoder = new TextEncoder();
const utf8Decoder = new TextDecoder("utf-8", { ignoreBOM: true });

With this --

"use strict";
var util= require('util');
const utf8Encoder = new util.TextEncoder();
const utf8Decoder = new util.TextDecoder("utf-8", { ignoreBOM: true });

Then you are good to go.

about 4 years ago · Juan Pablo Isaza Report

0

TextEncoder is not defined node error

This seems to be an issue with older node versions. You need to use the latest node. If you are using nvm type

nvm use node

Note: to download latest node with nvm use this command

nvm install --lts
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!