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

371
Vistas
Typescript: import { groupBy } from 'lodash' ReferenceError: require is not defined

I'm trying to use groupBy from lodash in a .ts file like this:

import { groupBy } from 'lodash';

But after tsc .\index.ts -w the resulting index.js turns that import into var lodash_1 = require("lodash"); and the following error appears:

index.js:28 Uncaught ReferenceError: require is not defined

Here is my package.json:

{
  "name": "final_exercise",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "lodash-es": "^4.17.21",
    "require": "^0.4.4",
    "typescript-require": "^0.3.0"
  }

The error happens with and without require and typescript-require being installed. Installing require needed the npm audit fix --force, not sure if that's normal or not.

tsconfig.json

{
  "compilerOptions": {
    "target": "ES2019",
    "module": "commonjs",
    "lib": ["ES2019", "dom", "dom.iterable"],
    "strict": true,
    "sourceMap": true,
  }
}

I also have this on the end of index.html, else the error would be ReferenceError: exports is not defined:

<script> var exports = {}; </script>
<script src="index.js"></script>

Since I'm new to Typescript, to modules and everything associated, I must be doing something wrong or I'm missing something. I've checked all similar questions with answers but nothing so far has worked.

Thanks for any help.

about 4 years ago · Santiago Trujillo
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