Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

304
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda