Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

423
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda