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

363
Views
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
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!