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

305
Visualizações
TextEncoder is not defined. Connecting to MongoDB on wsl2 with nodejs

I am trying to get a simple MERN app working on an Ubuntu wsl2 instance. I am following this guide. This is the code that I have in server.js (it is slightly different to the code in the guide as body-parser is deprecated. Using the advice from this post I've changed those methods).

const express = require("express");
const mongoose = require("mongoose");

// Setup express app
const app = express();

app.use(
    express.urlencoded({
        extended: false
    })
);

app.use(express.json());

// Configure Mongo
const db = "mongodb://localhost/313-demo-mern-db";

// Connect to Mongo with Mongoose
mongoose
    .connect(
        db,
        { useNewUrlParser: true }
    )
    .then(() => console.log("Mongo connected"))
    .catch(err => console.log(err));

// Specify the Port where the backend server can be accessed and start listening on that port
const port = process.env.PORT || 5000;
app.listen(port, () => console.log(`Server up and running on port ${port}.`));

I have a MongoDB database running where it is currently "Waiting for connections on port 27017". I run the command node server.js and get the error.

/home/NAME/learnreact/MERN-demo/node_modules/whatwg-url/dist/encoding.js:2
const utf8Encoder = new TextEncoder();
                    ^

ReferenceError: TextEncoder is not defined
    at Object.<anonymous> (/home/NAME/learnreact/MERN-demo/node_modules/whatwg-url/dist/encoding.js:2:21)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
    at Module.load (internal/modules/cjs/loader.js:653:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)
    at Module.require (internal/modules/cjs/loader.js:692:17)
    at require (internal/modules/cjs/helpers.js:25:18)
    at Object.<anonymous> (/home/NAME/learnreact/MERN-demo/node_modules/whatwg-url/dist/url-state-machine.js:5:34)
    at Module._compile (internal/modules/cjs/loader.js:778:30)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I was having the same error today. Updating the node to latest version fixed the issue for me.

You may refer https://askubuntu.com/a/480642/1267099 for updating node.

edit: update to the latest version (not the current stable)

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