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

141
Views
esbuild cannot resolve the Node.js module 'events'

One of my dependencies contains the following code

var EventEmitter = require('events').EventEmitter;

exports.EventEmitter = EventEmitter;
exports.mixin = mixin;

function mixin(Constructor) {
  for (var key in EventEmitter.prototype) {
    Constructor.prototype[key] = EventEmitter.prototype[key];
  }
}

I got the following error when trying to bundle everything into a file

$ npm run build


> gantt@0.0.0 build
> esbuild public/js/src/main.ts --bundle --minify --sourcemap --outfile=public/js/dest/bundled.js

 > node_modules/sharedb/lib/emitter.js:1:27: error: Could not resolve "events" (use "--platform=node" when building for node)
    1 │ var EventEmitter = require('events').EventEmitter;
      ╵                            ~~~~~~~~

1 error

I am targeting browsers, so it's impractical to have --platform=node. I discovered this issue when searching around, but the offending line is in a dependency, so I cannot simply edit its source to replace the CommonJS module import with an ES module import.

How can I point esbuild to the implementation of events?

about 4 years ago · Juan Pablo Isaza
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!